Skip to content

Commit a4e0dfa

Browse files
authored
Merge pull request #1469 from caternuson/milk_sniffer
add CLUE milk checker code
2 parents 0b1775a + 14645af commit a4e0dfa

File tree

5 files changed

+9343
-0
lines changed

5 files changed

+9343
-0
lines changed

CLUE_Milk_Checker/bmps/milk_bg.bmp

28.3 KB
Binary file not shown.
1.32 KB
Binary file not shown.

CLUE_Milk_Checker/code.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import time
2+
import board
3+
import terminalio
4+
import displayio
5+
import adafruit_sgp30
6+
from adafruit_bitmap_font import bitmap_font
7+
from adafruit_display_text import label
8+
import adafruit_imageload
9+
from adafruit_clue import clue
10+
11+
# --| User Config |-------------------------
12+
TVOC_LEVELS = (80, 120) # set two TVOC levels
13+
MESSAGES = ("GOOD", "SUS?", "BAD!") # set three messages (4 char max)
14+
# ------------------------------------------
15+
16+
# setup UI
17+
cow_bmp, cow_pal = adafruit_imageload.load("bmps/milk_bg.bmp")
18+
background = displayio.TileGrid(cow_bmp, pixel_shader=cow_pal)
19+
20+
mouth_bmp, mouth_pal = adafruit_imageload.load("bmps/mouth_sheet.bmp")
21+
mouth = displayio.TileGrid(
22+
mouth_bmp,
23+
pixel_shader=mouth_pal,
24+
tile_width=40,
25+
tile_height=20,
26+
width=1,
27+
height=1,
28+
x=35,
29+
y=110,
30+
)
31+
32+
msg_font = bitmap_font.load_font("fonts/Alphakind_28.bdf")
33+
msg_font.load_glyphs("".join(MESSAGES))
34+
message = label.Label(msg_font, text="WAIT", color=0x000000)
35+
message.anchor_point = (0.5, 0.5)
36+
message.anchored_position = (172, 38)
37+
38+
data_font = bitmap_font.load_font("fonts/F25_Bank_Printer_Bold_12.bdf")
39+
data_font.load_glyphs("eTVOC=12345?")
40+
tvoc = label.Label(data_font, text="TVOC=?????", color=0x000000)
41+
tvoc.anchor_point = (0, 1)
42+
tvoc.anchored_position = (5, 235)
43+
44+
eco2 = label.Label(data_font, text="eCO2=?????", color=0x000000)
45+
eco2.anchor_point = (0, 1)
46+
eco2.anchored_position = (130, 235)
47+
48+
splash = displayio.Group(max_size=5)
49+
splash.append(background)
50+
splash.append(mouth)
51+
splash.append(message)
52+
splash.append(tvoc)
53+
splash.append(eco2)
54+
clue.display.show(splash)
55+
56+
# setup SGP30 and wait for initial warm up
57+
sgp30 = adafruit_sgp30.Adafruit_SGP30(board.I2C())
58+
time.sleep(15)
59+
60+
# loop forever
61+
while True:
62+
eCO2, TVOC = sgp30.iaq_measure()
63+
64+
tvoc.text = "TVOC={:5d}".format(TVOC)
65+
eco2.text = "eCO2={:5d}".format(eCO2)
66+
67+
level = 0
68+
for thresh in TVOC_LEVELS:
69+
if TVOC <= thresh:
70+
break
71+
level += 1
72+
73+
if level <= len(TVOC_LEVELS):
74+
message.text = MESSAGES[level]
75+
mouth[0] = level
76+
else:
77+
message.text = "????"
78+
79+
time.sleep(1)

0 commit comments

Comments
 (0)