Skip to content

Commit 2e7b6d8

Browse files
committed
add milk checker code
1 parent 0b1775a commit 2e7b6d8

File tree

5 files changed

+9339
-0
lines changed

5 files changed

+9339
-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: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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(mouth_bmp, pixel_shader=mouth_pal,
22+
tile_width = 40,
23+
tile_height = 20,
24+
width = 1,
25+
height = 1,
26+
x = 35, y=110)
27+
28+
msg_font = bitmap_font.load_font("fonts/Alphakind_28.bdf")
29+
msg_font.load_glyphs("".join(MESSAGES))
30+
message = label.Label(msg_font, text="WAIT", color=0x000000)
31+
message.anchor_point = (0.5, 0.5)
32+
message.anchored_position = (172, 38)
33+
34+
data_font = bitmap_font.load_font("fonts/F25_Bank_Printer_Bold_12.bdf")
35+
data_font.load_glyphs("eTVOC=12345?")
36+
tvoc = label.Label(data_font, text="TVOC=?????", color=0x000000)
37+
tvoc.anchor_point = (0, 1)
38+
tvoc.anchored_position = (5, 235)
39+
40+
eco2 = label.Label(data_font, text="eCO2=?????", color=0x000000)
41+
eco2.anchor_point = (0, 1)
42+
eco2.anchored_position = (130, 235)
43+
44+
splash = displayio.Group(max_size=5)
45+
splash.append(background)
46+
splash.append(mouth)
47+
splash.append(message)
48+
splash.append(tvoc)
49+
splash.append(eco2)
50+
clue.display.show(splash)
51+
52+
# setup SGP30 and wait for initial warm up
53+
sgp30 = adafruit_sgp30.Adafruit_SGP30(board.I2C())
54+
time.sleep(15)
55+
56+
# loop forever
57+
while True:
58+
eCO2, TVOC = sgp30.iaq_measure()
59+
60+
tvoc.text = "TVOC={:5d}".format(TVOC)
61+
eco2.text = "eCO2={:5d}".format(eCO2)
62+
63+
level = 0
64+
for thresh in TVOC_LEVELS:
65+
if TVOC <= thresh:
66+
break
67+
level += 1
68+
69+
if level <= len(TVOC_LEVELS):
70+
message.text = MESSAGES[level]
71+
mouth[0] = level
72+
else:
73+
message.text = "????"
74+
75+
time.sleep(1)

0 commit comments

Comments
 (0)