-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhappy_plant.py
59 lines (46 loc) · 925 Bytes
/
happy_plant.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
from microbit import *
import math
KNOWN_RES = 1181
V_IN = 3
R_BAD = 900
R_OK = 700
BAD = (
(9, 9, 0, 9, 9),
(0, 9, 0, 9, 0),
(0, 0, 0, 0, 0),
(0, 9, 9, 9, 0),
(9, 0, 0, 0, 9),
)
OK = (
(0, 9, 0, 9, 0),
(0, 9, 0, 9, 0),
(0, 0, 0, 0, 0),
(9, 9, 9, 9, 9),
(0, 0, 0, 0, 0),
)
GOOD = (
(0, 9, 0, 9, 0),
(0, 9, 0, 9, 0),
(0, 0, 0, 0, 0),
(9, 0, 0, 0, 9),
(0, 9, 9, 9, 0),
)
def to_display(matrix):
for y, row in enumerate(matrix):
for x, col in enumerate(row):
display.set_pixel(x, y, col)
def get_res():
pin_val = pin0.read_analog()
v_out = (V_IN * pin_val) / 1023
return math.fabs(KNOWN_RES * (1 / (V_IN / v_out) - 1))
while True:
res = get_res()
print(res)
if res > R_BAD:
to_display(BAD)
elif res > R_OK:
to_display(OK)
else:
to_display(GOOD)
print(res)
sleep(500)