From 83e30aa72f168a831b5f64920c76ce435c836bc9 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Thu, 6 Feb 2020 11:50:15 -0500 Subject: [PATCH 1/3] Adding CLUE demos. --- examples/clue_height_calculator.py | 25 ++++++++++ examples/clue_spirit_level.py | 29 ++++++++++++ examples/clue_temperature_humidity_monitor.py | 47 +++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100755 examples/clue_height_calculator.py create mode 100755 examples/clue_spirit_level.py create mode 100755 examples/clue_temperature_humidity_monitor.py diff --git a/examples/clue_height_calculator.py b/examples/clue_height_calculator.py new file mode 100755 index 0000000..5df6dca --- /dev/null +++ b/examples/clue_height_calculator.py @@ -0,0 +1,25 @@ +"""Calculate the height of an object. Press button A to reset initial height and then lift the +CLUE to find the height.""" +from adafruit_clue import clue + +# Set to the sea level pressure in hPa at your location for the most accurate altitude measurement. +clue.sea_level_pressure = 1015 + +clue_data = clue.simple_text_display(text_scale=2, colors=((0, 255, 255), 0, (255, 0, 0), + (255, 0, 0), 0, (255, 255, 0), 0, + (0, 255, 0))) + +initial_height = clue.altitude + +clue_data[0].text = "Calculate height!" +clue_data[2].text = "Press A to reset" +clue_data[3].text = "initial height!" +while True: + if clue.button_a: + initial_height = clue.altitude + clue.pixel.fill((255, 0, 0)) + else: + clue.pixel.fill(0) + clue_data[5].text = "Altitude: {:.1f} m".format(clue.altitude) + clue_data[7].text = "Height: {:.1f} m".format(clue.altitude - initial_height) + clue_data.show() diff --git a/examples/clue_spirit_level.py b/examples/clue_spirit_level.py new file mode 100755 index 0000000..6b0b9ee --- /dev/null +++ b/examples/clue_spirit_level.py @@ -0,0 +1,29 @@ +"""CLUE Spirit Level Demo""" +import board +from adafruit_clue import clue +from adafruit_display_shapes.circle import Circle +import displayio + +display = board.DISPLAY +group = displayio.Group(max_size=4) + +outer_circle = Circle(120, 120, 119, outline=(255, 255, 255)) +middle_circle = Circle(120, 120, 75, outline=(255, 255, 0)) +inner_circle = Circle(120, 120, 35, outline=(0, 255, 0)) +group.append(outer_circle) +group.append(middle_circle) +group.append(inner_circle) + +x, y, _ = clue.acceleration +bubble_group = displayio.Group(max_size=1) +level_bubble = Circle(int(x + 120), int(y + 120), 20, fill=(255, 0, 0), outline=(255, 0, 0)) +bubble_group.append(level_bubble) + +group.append(bubble_group) +display.show(group) + +while True: + x, y, _ = clue.acceleration + bubble_group.x = int(x * 10) + bubble_group.y = int(y * 10) + display.show(group) diff --git a/examples/clue_temperature_humidity_monitor.py b/examples/clue_temperature_humidity_monitor.py new file mode 100755 index 0000000..5c0388a --- /dev/null +++ b/examples/clue_temperature_humidity_monitor.py @@ -0,0 +1,47 @@ +"""Monitor customisable temperature and humidity ranges, with an optional alarm.""" +from adafruit_clue import clue + +# Set desired temperature range in degrees Celsius. +min_temp = 24 +max_temp = 30 + +# Set desired humidity range in percent. +min_humidity = 20 +max_humidity = 65 + +# Set to true to enable alarm warning. +alarm = False + +data = clue.simple_text_display(text_scale=3, colors=((255, 255, 255),)) + +data[0].text = "Temperature &" +data[1].text = "Humidity" +while True: + alarm = False + temperature = clue.temperature + humidity = clue.humidity + data[3].text = "Temp: {:.1f} C".format(temperature) + data[5].text = "Humi: {:.1f} %".format(humidity) + if temperature < min_temp: + data[3].color = (0, 0, 255) + alarm = True + elif temperature > max_temp: + data[3].color = (255, 0, 0) + alarm = True + else: + data[3].color = (255, 255, 255) + + if humidity < min_humidity: + data[5].color = (0, 0, 255) + alarm = True + elif humidity > max_humidity: + data[5].color = (255, 0, 0) + alarm = True + else: + data[5].color = (255, 255, 255) + data.show() + + if alarm: + clue.start_tone(2000) + else: + clue.stop_tone() From 10141329953fb4707dc9d673f8884df017f497ee Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Thu, 6 Feb 2020 11:56:07 -0500 Subject: [PATCH 2/3] Remove unnecessary show() --- examples/clue_spirit_level.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/clue_spirit_level.py b/examples/clue_spirit_level.py index 6b0b9ee..757f3cc 100755 --- a/examples/clue_spirit_level.py +++ b/examples/clue_spirit_level.py @@ -26,4 +26,3 @@ x, y, _ = clue.acceleration bubble_group.x = int(x * 10) bubble_group.y = int(y * 10) - display.show(group) From ee9954aea8ffc78f882496c71b588b00a35f922d Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Thu, 6 Feb 2020 12:24:12 -0500 Subject: [PATCH 3/3] Add color variables, update alarm. --- adafruit_clue.py | 28 +++++++++++++++++-- examples/clue_height_calculator.py | 6 ++-- examples/clue_spirit_level.py | 8 +++--- examples/clue_temperature_humidity_monitor.py | 18 ++++++------ 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/adafruit_clue.py b/adafruit_clue.py index c4b82e0..628a2db 100644 --- a/adafruit_clue.py +++ b/adafruit_clue.py @@ -85,8 +85,8 @@ def __init__(self, title=None, title_color=0xFFFFFF, title_scale=1, # pylint: from adafruit_display_text import label if not colors: - colors = ((255, 0, 255), (0, 255, 0), (255, 0, 0), (0, 255, 255), (255, 255, 0), - (0, 0, 255), (255, 0, 180), (0, 180, 255), (255, 180, 0), (180, 0, 255)) + colors = (Clue.VIOLET, Clue.GREEN, Clue.RED, Clue.CYAN, Clue.ORANGE, + Clue.BLUE, Clue.MAGENTA, Clue.SKY, Clue.YELLOW, Clue.PURPLE) self._colors = colors self._label = label @@ -143,6 +143,30 @@ def show_terminal(self): class Clue: # pylint: disable=too-many-instance-attributes, too-many-public-methods """Represents a single CLUE.""" + + # Color variables available for import. + RED = (255, 0, 0) + YELLOW = (255, 255, 0) + ORANGE = (255, 150, 0) + GREEN = (0, 255, 0) + TEAL = (0, 255, 120) + CYAN = (0, 255, 255) + BLUE = (0, 0, 255) + PURPLE = (180, 0, 255) + MAGENTA = (255, 0, 150) + WHITE = (255, 255, 255) + BLACK = (0, 0, 0) + + GOLD = (255, 222, 30) + PINK = (242, 90, 255) + AQUA = (50, 255, 255) + JADE = (0, 255, 40) + AMBER = (255, 100, 0) + VIOLET = (255, 0, 255) + SKY = (0, 180, 255) + + RAINBOW = (RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE) + def __init__(self): # Define I2C: self._i2c = board.I2C() diff --git a/examples/clue_height_calculator.py b/examples/clue_height_calculator.py index 5df6dca..58db9ab 100755 --- a/examples/clue_height_calculator.py +++ b/examples/clue_height_calculator.py @@ -5,9 +5,9 @@ # Set to the sea level pressure in hPa at your location for the most accurate altitude measurement. clue.sea_level_pressure = 1015 -clue_data = clue.simple_text_display(text_scale=2, colors=((0, 255, 255), 0, (255, 0, 0), - (255, 0, 0), 0, (255, 255, 0), 0, - (0, 255, 0))) +clue_data = clue.simple_text_display(text_scale=2, colors=(clue.CYAN, 0, clue.RED, clue.RED, 0, + clue.YELLOW, 0, clue.GREEN)) + initial_height = clue.altitude diff --git a/examples/clue_spirit_level.py b/examples/clue_spirit_level.py index 757f3cc..32fc75d 100755 --- a/examples/clue_spirit_level.py +++ b/examples/clue_spirit_level.py @@ -7,16 +7,16 @@ display = board.DISPLAY group = displayio.Group(max_size=4) -outer_circle = Circle(120, 120, 119, outline=(255, 255, 255)) -middle_circle = Circle(120, 120, 75, outline=(255, 255, 0)) -inner_circle = Circle(120, 120, 35, outline=(0, 255, 0)) +outer_circle = Circle(120, 120, 119, outline=clue.WHITE) +middle_circle = Circle(120, 120, 75, outline=clue.YELLOW) +inner_circle = Circle(120, 120, 35, outline=clue.GREEN) group.append(outer_circle) group.append(middle_circle) group.append(inner_circle) x, y, _ = clue.acceleration bubble_group = displayio.Group(max_size=1) -level_bubble = Circle(int(x + 120), int(y + 120), 20, fill=(255, 0, 0), outline=(255, 0, 0)) +level_bubble = Circle(int(x + 120), int(y + 120), 20, fill=clue.RED, outline=clue.RED) bubble_group.append(level_bubble) group.append(bubble_group) diff --git a/examples/clue_temperature_humidity_monitor.py b/examples/clue_temperature_humidity_monitor.py index 5c0388a..3de3b40 100755 --- a/examples/clue_temperature_humidity_monitor.py +++ b/examples/clue_temperature_humidity_monitor.py @@ -10,9 +10,9 @@ max_humidity = 65 # Set to true to enable alarm warning. -alarm = False +alarm_enable = False -data = clue.simple_text_display(text_scale=3, colors=((255, 255, 255),)) +data = clue.simple_text_display(text_scale=3, colors=(clue.WHITE,)) data[0].text = "Temperature &" data[1].text = "Humidity" @@ -23,25 +23,25 @@ data[3].text = "Temp: {:.1f} C".format(temperature) data[5].text = "Humi: {:.1f} %".format(humidity) if temperature < min_temp: - data[3].color = (0, 0, 255) + data[3].color = clue.BLUE alarm = True elif temperature > max_temp: - data[3].color = (255, 0, 0) + data[3].color = clue.RED alarm = True else: - data[3].color = (255, 255, 255) + data[3].color = clue.WHITE if humidity < min_humidity: - data[5].color = (0, 0, 255) + data[5].color = clue.BLUE alarm = True elif humidity > max_humidity: - data[5].color = (255, 0, 0) + data[5].color = clue.RED alarm = True else: - data[5].color = (255, 255, 255) + data[5].color = clue.WHITE data.show() - if alarm: + if alarm and alarm_enable: clue.start_tone(2000) else: clue.stop_tone()