Hilfe bei Fehlern in der Programmierung mit Python
Verfasst: Freitag 28. Februar 2014, 11:02
Hallo,
ich, als Python-Neuling, musste mich jetzt einmal bei Euch anmelden, da ich von allein nicht auf den Fehler komme und auch die SuFu mich nicht weiter bringt.
Ich habe mehrer kleinere Programme zum ansteuern einer selbst gelöteten 6ér LED-Leiste geschrieben und möchte diese jetzt mit einem Pseudo-Random-Befehl wechseln lassen. Die einzelnen Programme für die LED´s laufen einwandfrei und mein Versuch mit random.randint funktioniert auch.
Nur die Kombination mit beiden will mein Pie nicht.
Der Fehler soll in Zeile 97 liegen. Ein Syntaxfehler bei
Allerdings übersteigt die Fehlersuche da meine Kompetenzen und ich wäre Euch sehr dankbar, wenn Ihr mir da weiterhelfen könntet.
Eventuell gibt es ja auch eine andere Möglichkeit die LED-Programme "zufällig" Auszuwählen.
Hier mal die Pseydo-Random
Und hier der Versuch alles zu implementieren.
VG JR
ich, als Python-Neuling, musste mich jetzt einmal bei Euch anmelden, da ich von allein nicht auf den Fehler komme und auch die SuFu mich nicht weiter bringt.
Ich habe mehrer kleinere Programme zum ansteuern einer selbst gelöteten 6ér LED-Leiste geschrieben und möchte diese jetzt mit einem Pseudo-Random-Befehl wechseln lassen. Die einzelnen Programme für die LED´s laufen einwandfrei und mein Versuch mit random.randint funktioniert auch.
Nur die Kombination mit beiden will mein Pie nicht.
Der Fehler soll in Zeile 97 liegen. Ein Syntaxfehler bei
Code: Alles auswählen
if i==2: #Programm Lauflicht 2, bei Auswahl von 2.
Eventuell gibt es ja auch eine andere Möglichkeit die LED-Programme "zufällig" Auszuwählen.
Hier mal die Pseydo-Random
Code: Alles auswählen
import random
import time
random.seed()
i = 1
try:
if i:
i = random.randint(1,3)
if i == 1:
print "Hello"
if i == 2:
print "my Name is"
if i == 3:
print "Dr. Greenthumb"
time.sleep(2)
except KeyboardInterrupt:
print "Fin"
VG JR
Code: Alles auswählen
import RPi. GPIO as GPIO
import time
import random
a=0.05
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(07, GPIO.OUT)
GPIO.setup(11, GPIO.OUT)
GPIO.setup(12, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)
GPIO.setup(16, GPIO.OUT)
random.seed() #Randombefehl
i=1
try:
if i:
i=random.randint(1,3) #Auswahl zwischen 1,2,3
if i==1: #Programm Lauflicht 1, bei Auswahl der 1.
GPIO.output(07,GPIO.HIGH)
time.sleep(a)
GPIO.output(11,GPIO.HIGH)
time.sleep(a)
GPIO.output(07,GPIO.LOW)
time.sleep(a)
GPIO.output(13,GPIO.HIGH)
time.sleep(a)
GPIO.output(11,GPIO.LOW)
time.sleep(a)
GPIO.output(15,GPIO.HIGH)
time.sleep(a)
GPIO.output(13,GPIO.LOW)
time.sleep(a)
GPIO.output(12,GPIO.HIGH)
time.sleep(a)
GPIO.output(15,GPIO.LOW)
time.sleep(a)
GPIO.output(16,GPIO.HIGH)
time.sleep(a)
GPIO.output(12,GPIO.LOW)
time.sleep(a)
GPIO.output(07,GPIO.HIGH)
time.sleep(a)
GPIO.output(16,GPIO.LOW)
time.sleep(a)
GPIO.output(07,GPIO.LOW
if i==2: #Programm Lauflicht 2, bei Auswahl von 2.
GPIO.output(07,GPIO.HIGH)
time.sleep(a)
GPIO.output(11,GPIO.HIGH)
time.sleep(a)
GPIO.output(07,GPIO.LOW)
time.sleep(a)
GPIO.output(13,GPIO.HIGH)
time.sleep(a)
GPIO.output(11,GPIO.LOW)
time.sleep(a)
GPIO.output(15,GPIO.HIGH)
time.sleep(a)
GPIO.output(13,GPIO.LOW)
time.sleep(a)
GPIO.output(12,GPIO.HIGH)
time.sleep(a)
GPIO.output(15,GPIO.LOW)
time.sleep(a)
GPIO.output(16,GPIO.HIGH)
time.sleep(a)
GPIO.output(12,GPIO.HIGH)
time.sleep(a)
GPIO.output(16,GPIO.LOW)
time.sleep(a)
GPIO.output(15,GPIO.HIGH)
time.sleep(a)
GPIO.output(12,GPIO.LOW)
time.sleep(a)
GPIO.output(13,GPIO.HIGH)
time.sleep(a)
GPIO.output(15,GPIO.LOW)
time.sleep(a)
GPIO.output(11,GPIO.HIGH)
time.sleep(a)
GPIO.output(13,GPIO.LOW)
time.sleep(a)
GPIO.output(07,GPIO.HIGH)
if i==3: #Programm Lauflicht 3, bei Auswahl der 3.
GPIO.output(07,GPIO.HIGH)
GPIO.output(15,GPIO.HIGH)
time.sleep(a)
GPIO.output(11,GPIO.HIGH)
GPIO.output(12,GPIO.HIGH)
time.sleep(a)
GPIO.output(07,GPIO.LOW)
GPIO.output(15,GPIO.LOW)
time.sleep(a)
GPIO.output(13,GPIO.HIGH)
GPIO.output(16,GPIO.HIGH)
time.sleep(a)
GPIO.output(07,GPIO.HIGH)
GPIO.output(15,GPIO.HIGH)
time.sleep(a)
GPIO.output(11,GPIO.LOW)
GPIO.output(12,GPIO.LOW)
time.sleep(a)
GPIO.output(13,GPIO.LOW)
time.sleep(a)
GPIO.output(16,GPIO.LOW)
except KeyboardInterrupt:
print: "Fin"
GPIO.cleanup()