je ne sait pas a quoi servent les autres definition vu que tu ne ten sert pas ?
je débute en python mais Voila comment je voit la chose :
Code : Tout sélectionner
import os
import time
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
CONSIGNE = 20
LEDVERTE = 18
LEDROUGE = 17
def temperature():
global temp
tfile = open("/sys/bus/w1/devices/28-000006a3375b/w1_slave")
text = tfile.read()
tfile.close()
temperaturedata = text.split("\n")[1].split(" ")[9]
temperature = float(temperaturedata[2:])
temp = round(temperature / 1000, 2)
def froid(): # La Temp est inf a la consigne
GPIO.output(LEDVERTE,GPIO.LOW)
GPIO.output(LEDROUGE,GPIO.HIGH)
print "froid"
def chaud(): # La temp est sup a la consigne
print "chaud"
GPIO.output(LEDVERTE,GPIO.HIGH)
GPIO.output(LEDROUGE,GPIO.LOW)
def panic():
print "panic" # les deux leds s'allument si anomalie
GPIO.output(LEDVERTE,GPIO.HIGH)
GPIO.output(LEDROUGE,GPIO.HIGH)
while True:
if temp >= CONSIGNE:
chaud()
elif temp < CONSIGNE:
froid()
else:
panic()
time.sleep(30)