-
Notifications
You must be signed in to change notification settings - Fork 1
/
temp.py
35 lines (27 loc) · 808 Bytes
/
temp.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
#!/usr/bin/env python3
#
# use thermistor + 8k2ohm resistor to GND, mid point to adc, when warm light up red LED, else green
# ain(1) is CH2 on pin 2 of the MCP3008
# threshold has to be chosen by experiment
import adc
import RPi.GPIO as GPIO
from time import sleep
RED = 13
GREEN = 26
GPIO.setmode(GPIO.BCM)
GPIO.setup(RED, GPIO.OUT)
GPIO.setup(GREEN, GPIO.OUT)
try:
while True:
t = adc.get_ain(1)
print( t )
if t > 800 :
GPIO.output(RED,GPIO.LOW)
GPIO.output(GREEN,GPIO.HIGH)
else :
GPIO.output(GREEN,GPIO.LOW)
GPIO.output(RED,GPIO.HIGH)
sleep(0.3)
# this catches when you stop the program to turn off LEDs
except KeyboardInterrupt:
GPIO.cleanup()