-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththermometer.py
89 lines (74 loc) · 2.41 KB
/
thermometer.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
# Write your code here :-)
# CircuitPlaygroundExpress_Temperature
# reads the on-board temperature sensor and prints the value
import adafruit_thermistor
import digitalio
import board
import time
import neopixel
thermistor = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000, 10000, 25, 3950)
tempUp = digitalio.DigitalInOut(board.BUTTON_A)
tempUp.direction = digitalio.Direction.INPUT
tempUp.pull = digitalio.Pull.DOWN
tempDown = digitalio.DigitalInOut(board.BUTTON_B)
tempDown.direction = digitalio.Direction.INPUT
tempDown.pull = digitalio.Pull.DOWN
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=.2)
pixels.show()
def wheel(pixelCount):
color = (0, 0, 0)
if pixelCount == 1:
color = (0x10, 0, 0x10)
elif pixelCount == 2:
color = (0x10, 0, 0x10)
elif pixelCount == 3:
color = (0, 0, 0x10)
elif pixelCount == 4:
color = (0, 0x10, 0)
elif pixelCount == 5:
color = (0, 0x10, 0)
elif pixelCount == 6:
color = (0x10, 0x10, 0)
elif pixelCount == 7:
color = (0x10, 0x10, 0)
elif pixelCount == 8:
color = (0x10, 0, 0)
elif pixelCount == 9:
color = (0x10, 0, 0)
elif pixelCount == 10:
color = (0x10, 0, 0)
for i in range(pixelCount):
pixels[i] = color
for i in range(pixelCount, 10, 1):
pixels[i] = (0, 0, 0)
tuningFactor = 0.5
center = 23
spread = 1
while True:
if tempUp.value:
center = center + 1
if tempDown.value:
center = center - 1
if(abs(thermistor.temperature-center-4*spread) < tuningFactor):
wheel(1)
if(abs(thermistor.temperature-center-3*spread) < tuningFactor):
wheel(2)
if(abs(thermistor.temperature-center-2*spread) < tuningFactor):
wheel(3)
if(abs(thermistor.temperature-center-spread) < tuningFactor):
wheel(4)
if(abs(thermistor.temperature-center) < tuningFactor):
wheel(5)
if(abs(thermistor.temperature-center+spread) < tuningFactor):
wheel(6)
if(abs(thermistor.temperature-center+2*spread) < tuningFactor):
wheel(7)
if(abs(thermistor.temperature-center+3*spread) < tuningFactor):
wheel(8)
if(abs(thermistor.temperature-center+4*spread) < tuningFactor):
wheel(9)
if(abs(thermistor.temperature-center+5*spread) < tuningFactor):
wheel(10)
pixels.show
print(thermistor.temperature)
time.sleep(0.1)