Skip to content

Adding CLUE demos. #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions examples/clue_height_calculator.py
Original file line number Diff line number Diff line change
@@ -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()
29 changes: 29 additions & 0 deletions examples/clue_spirit_level.py
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think you need this line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accurate. Removing.

47 changes: 47 additions & 0 deletions examples/clue_temperature_humidity_monitor.py
Original file line number Diff line number Diff line change
@@ -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()