I'd like some help getting this python code to work with my Raspberry Pi. The goal is to turn on 1 of 3 LED's at a time (Green, Yellow, and Red) based on a CPU Temperature Range.
This means:
- Green LED needs to turn ON when temperature range is less than 32ºC.
- Red LED ON if temperature is greater than 37ºC.
- Then Yellow LED ON if temperature is greater than 31ºC or less than 37ºC.
I'm a newbie at coding, so far I can get the temperature to print and only the Red LED turns on and stays on regardless of CPU temperature.
import os
import time
import RPi.GPIO as GPIO
#GREEN=11
#YELLOW=10
#RED=9
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(11,GPIO.OUT)
GPIO.setup(10,GPIO.OUT)
GPIO.setup(9,GPIO.OUT)
def measure_temp():
temp = os.popen("vcgencmd measure_temp").readline()
return (temp.replace("temp=","").replace("'C",""))
while True:
measure_temp()
if measure_temp<32:
GPIO.output(11,GPIO.HIGH)
GPIO.output(10,GPIO.LOW)
GPIO.output(9,GPIO.LOW)
if measure_temp>37:
GPIO.output(9,GPIO.HIGH)
GPIO.output(10,GPIO.LOW)
GPIO.output(11,GPIO.LOW)
if measure_temp>32 or <37
GPIO.output(10,GPIO.HIGH)
GPIO.output(11,GPIO.LOW)
GPIO.output(9,GPIO.LOW)
print(measure_temp())
#cleanup
c.close()
GPIO.cleanup()