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 new file mode 100755 index 0000000..58db9ab --- /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=(clue.CYAN, 0, clue.RED, clue.RED, 0, + clue.YELLOW, 0, clue.GREEN)) + + +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..32fc75d --- /dev/null +++ b/examples/clue_spirit_level.py @@ -0,0 +1,28 @@ +"""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=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=clue.RED, outline=clue.RED) +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) diff --git a/examples/clue_temperature_humidity_monitor.py b/examples/clue_temperature_humidity_monitor.py new file mode 100755 index 0000000..3de3b40 --- /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_enable = False + +data = clue.simple_text_display(text_scale=3, colors=(clue.WHITE,)) + +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 = clue.BLUE + alarm = True + elif temperature > max_temp: + data[3].color = clue.RED + alarm = True + else: + data[3].color = clue.WHITE + + if humidity < min_humidity: + data[5].color = clue.BLUE + alarm = True + elif humidity > max_humidity: + data[5].color = clue.RED + alarm = True + else: + data[5].color = clue.WHITE + data.show() + + if alarm and alarm_enable: + clue.start_tone(2000) + else: + clue.stop_tone()