Skip to content

Commit 3c610de

Browse files
authored
Merge pull request #7 from kattni/clue-demos
Adding CLUE demos.
2 parents 17918c7 + ee9954a commit 3c610de

File tree

4 files changed

+126
-2
lines changed

4 files changed

+126
-2
lines changed

adafruit_clue.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def __init__(self, title=None, title_color=0xFFFFFF, title_scale=1, # pylint:
8585
from adafruit_display_text import label
8686

8787
if not colors:
88-
colors = ((255, 0, 255), (0, 255, 0), (255, 0, 0), (0, 255, 255), (255, 255, 0),
89-
(0, 0, 255), (255, 0, 180), (0, 180, 255), (255, 180, 0), (180, 0, 255))
88+
colors = (Clue.VIOLET, Clue.GREEN, Clue.RED, Clue.CYAN, Clue.ORANGE,
89+
Clue.BLUE, Clue.MAGENTA, Clue.SKY, Clue.YELLOW, Clue.PURPLE)
9090

9191
self._colors = colors
9292
self._label = label
@@ -143,6 +143,30 @@ def show_terminal(self):
143143

144144
class Clue: # pylint: disable=too-many-instance-attributes, too-many-public-methods
145145
"""Represents a single CLUE."""
146+
147+
# Color variables available for import.
148+
RED = (255, 0, 0)
149+
YELLOW = (255, 255, 0)
150+
ORANGE = (255, 150, 0)
151+
GREEN = (0, 255, 0)
152+
TEAL = (0, 255, 120)
153+
CYAN = (0, 255, 255)
154+
BLUE = (0, 0, 255)
155+
PURPLE = (180, 0, 255)
156+
MAGENTA = (255, 0, 150)
157+
WHITE = (255, 255, 255)
158+
BLACK = (0, 0, 0)
159+
160+
GOLD = (255, 222, 30)
161+
PINK = (242, 90, 255)
162+
AQUA = (50, 255, 255)
163+
JADE = (0, 255, 40)
164+
AMBER = (255, 100, 0)
165+
VIOLET = (255, 0, 255)
166+
SKY = (0, 180, 255)
167+
168+
RAINBOW = (RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE)
169+
146170
def __init__(self):
147171
# Define I2C:
148172
self._i2c = board.I2C()

examples/clue_height_calculator.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Calculate the height of an object. Press button A to reset initial height and then lift the
2+
CLUE to find the height."""
3+
from adafruit_clue import clue
4+
5+
# Set to the sea level pressure in hPa at your location for the most accurate altitude measurement.
6+
clue.sea_level_pressure = 1015
7+
8+
clue_data = clue.simple_text_display(text_scale=2, colors=(clue.CYAN, 0, clue.RED, clue.RED, 0,
9+
clue.YELLOW, 0, clue.GREEN))
10+
11+
12+
initial_height = clue.altitude
13+
14+
clue_data[0].text = "Calculate height!"
15+
clue_data[2].text = "Press A to reset"
16+
clue_data[3].text = "initial height!"
17+
while True:
18+
if clue.button_a:
19+
initial_height = clue.altitude
20+
clue.pixel.fill((255, 0, 0))
21+
else:
22+
clue.pixel.fill(0)
23+
clue_data[5].text = "Altitude: {:.1f} m".format(clue.altitude)
24+
clue_data[7].text = "Height: {:.1f} m".format(clue.altitude - initial_height)
25+
clue_data.show()

examples/clue_spirit_level.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""CLUE Spirit Level Demo"""
2+
import board
3+
from adafruit_clue import clue
4+
from adafruit_display_shapes.circle import Circle
5+
import displayio
6+
7+
display = board.DISPLAY
8+
group = displayio.Group(max_size=4)
9+
10+
outer_circle = Circle(120, 120, 119, outline=clue.WHITE)
11+
middle_circle = Circle(120, 120, 75, outline=clue.YELLOW)
12+
inner_circle = Circle(120, 120, 35, outline=clue.GREEN)
13+
group.append(outer_circle)
14+
group.append(middle_circle)
15+
group.append(inner_circle)
16+
17+
x, y, _ = clue.acceleration
18+
bubble_group = displayio.Group(max_size=1)
19+
level_bubble = Circle(int(x + 120), int(y + 120), 20, fill=clue.RED, outline=clue.RED)
20+
bubble_group.append(level_bubble)
21+
22+
group.append(bubble_group)
23+
display.show(group)
24+
25+
while True:
26+
x, y, _ = clue.acceleration
27+
bubble_group.x = int(x * 10)
28+
bubble_group.y = int(y * 10)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""Monitor customisable temperature and humidity ranges, with an optional alarm."""
2+
from adafruit_clue import clue
3+
4+
# Set desired temperature range in degrees Celsius.
5+
min_temp = 24
6+
max_temp = 30
7+
8+
# Set desired humidity range in percent.
9+
min_humidity = 20
10+
max_humidity = 65
11+
12+
# Set to true to enable alarm warning.
13+
alarm_enable = False
14+
15+
data = clue.simple_text_display(text_scale=3, colors=(clue.WHITE,))
16+
17+
data[0].text = "Temperature &"
18+
data[1].text = "Humidity"
19+
while True:
20+
alarm = False
21+
temperature = clue.temperature
22+
humidity = clue.humidity
23+
data[3].text = "Temp: {:.1f} C".format(temperature)
24+
data[5].text = "Humi: {:.1f} %".format(humidity)
25+
if temperature < min_temp:
26+
data[3].color = clue.BLUE
27+
alarm = True
28+
elif temperature > max_temp:
29+
data[3].color = clue.RED
30+
alarm = True
31+
else:
32+
data[3].color = clue.WHITE
33+
34+
if humidity < min_humidity:
35+
data[5].color = clue.BLUE
36+
alarm = True
37+
elif humidity > max_humidity:
38+
data[5].color = clue.RED
39+
alarm = True
40+
else:
41+
data[5].color = clue.WHITE
42+
data.show()
43+
44+
if alarm and alarm_enable:
45+
clue.start_tone(2000)
46+
else:
47+
clue.stop_tone()

0 commit comments

Comments
 (0)