-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathfancy_plant_sensor.py
90 lines (86 loc) · 2.51 KB
/
fancy_plant_sensor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from adafruit_circuitplayground.express import cpx
from time import sleep
import touchio
from board import *
# temperature and light sensors, plus light output and sound. thresholds to be adjusted as needed.
while True:
if cpx.switch:
if cpx.button_a:
print('Temperature: ', cpx.temperature)
if cpx.temperature <= 21.0:
temp1_count = 0
while temp1_count < 3:
cpx.play_tone(262, 1.0)
temp1_count += 1
cpx.pixels.fill((0, 102, 255))
elif cpx.temperature >= 35.0:
temp2_count = 0
while temp2_count < 3:
cpx.play_tone(294, 1.0)
temp2_count += 1
cpx.pixels.fill((255, 51, 0))
else:
cpx.pixels.fill((0, 255, 0))
sleep(0.5)
cpx.pixels.fill((0, 0, 0))
if cpx.button_b:
print('Light Value: ', cpx.light)
cpx.pixels.fill((255, 255, 0))
sleep(0.5)
cpx.pixels.fill((0, 0, 0))
else:
#moisture sensor. fancy light output included. same thing on thresholds here.
touch = touchio.TouchIn(A1)
if cpx.button_a:
print('Moisture Level: ', touch.raw_value)
sleep(2.0)
if touch.raw_value < 1500:
cpx.play_tone(262, 1.0)
cpx.pixels.fill((51, 204,51))
sleep(0.5)
cpx.pixels[0] = (0, 0, 0)
sleep(0.2)
cpx.pixels[1] = (0, 0, 0)
sleep(0.2)
cpx.pixels[2] = (0, 0, 0)
sleep(0.2)
cpx.pixels[3] = (0, 0, 0)
sleep(0.2)
cpx.pixels[4] = (0, 0, 0)
sleep(0.2)
cpx.pixels[5] = (0, 0, 0)
sleep(0.2)
cpx.pixels[6] = (0, 0, 0)
sleep(0.2)
cpx.pixels[7] = (0, 0, 0)
sleep(0.2)
cpx.pixels[8] = (0, 0, 0)
sleep(0.2)
cpx.pixels[9] = (0, 0, 0)
cpx.pixels.fill((0, 0, 0))
else:
cpx.pixels.fill((51, 204, 51))
sleep(0.5)
cpx.pixels.fill((0, 0, 0))
cpx.pixels[0] = (51, 204, 51)
sleep(0.2)
cpx.pixels[1] = (51, 204, 51)
sleep(0.2)
cpx.pixels[2] = (51, 204, 51)
sleep(0.2)
cpx.pixels[3] = (51, 204, 51)
sleep(0.2)
cpx.pixels[4] = (51, 204, 51)
sleep(0.2)
cpx.pixels[5] = (51, 204, 51)
sleep(0.2)
cpx.pixels[6] = (51, 204, 51)
sleep(0.2)
cpx.pixels[7] = (51, 204, 51)
sleep(0.2)
cpx.pixels[8] = (51, 204, 51)
sleep(0.2)
cpx.pixels[9] = (51, 204, 51)
cpx.pixels.fill((51, 204, 51))
sleep(0.2)
cpx.pixels.fill((0, 0, 0))