clue_height_calculator.py
1 # SPDX-FileCopyrightText: 2019 Kattni Rembor, written for Adafruit Industries 2 # 3 # SPDX-License-Identifier: Unlicense 4 """Calculate the height of an object. Press button A to reset initial height and then lift the 5 CLUE to find the height.""" 6 from adafruit_clue import clue 7 8 # Set to the sea level pressure in hPa at your location for the most accurate altitude measurement. 9 clue.sea_level_pressure = 1015 10 11 clue_display = clue.simple_text_display( 12 text_scale=2, 13 colors=(clue.CYAN, 0, clue.RED, clue.RED, 0, clue.YELLOW, 0, clue.GREEN), 14 ) 15 16 initial_height = clue.altitude 17 18 clue_display[0].text = "Calculate height!" 19 clue_display[2].text = "Press A to reset" 20 clue_display[3].text = "initial height!" 21 22 while True: 23 if clue.button_a: 24 initial_height = clue.altitude 25 clue.pixel.fill(clue.RED) 26 else: 27 clue.pixel.fill(0) 28 29 clue_display[5].text = "Altitude: {:.1f} m".format(clue.altitude) 30 clue_display[7].text = "Height: {:.1f} m".format(clue.altitude - initial_height) 31 clue_display.show()