Ich baue ein Aquariumsteuerung mit RPi. Technik ist schon fertig, einzelne teile funktionieren.
Programieren lerne ich jetzt.
der Plan ist:
Steuerung durch PHP und Python:
PHP Seite ist schon fertig, aber mit Python geht es irgendwie nicht. Es soll erst 3 Optionen bekommen.
- ein
- aus
- Timer
Code lautet wie folgt:
Code: Alles auswählen
from __future__ import division
import time
from datetime import datetime, timedelta
import Adafruit_PCA9685
pwm = Adafruit_PCA9685.PCA9685(address=0x40)
pwm.set_pwm_freq(100)
while True:
dimmer=open("/var/www/html/dimmer.txt","r")
start=open("/var/www/html/start.txt","r")
ein=open("/var/www/html/ein.txt","r")
aus=open("/var/www/html/aus.txt","r")
a=0
fmax=4096
now=time.strftime("%H:%M")
on=start.read()
fdimm=int(fmax/100)*int(dimmer.read())
dimm=(1/(fdimm/30))
if on=="0" and a>0:
a=a-1
if on=="1" and a<fdimm:
a=a+1
if on=="2" and a<fdimm and now>=time.strftime(ein.read()) and now<time.strftime(aus.read()):
a=a+1
if on=="2" and a>0 and now>=time.strftime(aus.read()) and now<=time.strftime(23,59):
a=a-1
if on=="2" and a>0 and now<time.strftime(ein.read()) and now>=time.strftime(0,0):
a=a-1
pwm.set_pwm(0, 0, a)
pwm.set_pwm(1, 0, a)
pwm.set_pwm(2, 0, a)
time.sleep(dimm)
dimmer.close()
start.close()
ein.close()
aus.close()
Vielen Dank voraus
mfG
Istvan