Skip to content

Commit 83e30aa

Browse files
committed
Adding CLUE demos.
1 parent 17918c7 commit 83e30aa

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

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=((0, 255, 255), 0, (255, 0, 0),
9+
(255, 0, 0), 0, (255, 255, 0), 0,
10+
(0, 255, 0)))
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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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=(255, 255, 255))
11+
middle_circle = Circle(120, 120, 75, outline=(255, 255, 0))
12+
inner_circle = Circle(120, 120, 35, outline=(0, 255, 0))
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=(255, 0, 0), outline=(255, 0, 0))
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)
29+
display.show(group)
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 = False
14+
15+
data = clue.simple_text_display(text_scale=3, colors=((255, 255, 255),))
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 = (0, 0, 255)
27+
alarm = True
28+
elif temperature > max_temp:
29+
data[3].color = (255, 0, 0)
30+
alarm = True
31+
else:
32+
data[3].color = (255, 255, 255)
33+
34+
if humidity < min_humidity:
35+
data[5].color = (0, 0, 255)
36+
alarm = True
37+
elif humidity > max_humidity:
38+
data[5].color = (255, 0, 0)
39+
alarm = True
40+
else:
41+
data[5].color = (255, 255, 255)
42+
data.show()
43+
44+
if alarm:
45+
clue.start_tone(2000)
46+
else:
47+
clue.stop_tone()

0 commit comments

Comments
 (0)