-
IT café
Huawei P9-P9 Lite OFF topik
Új hozzászólás Aktív témák
-
petya220
senior tag
Valaki programozó közülünk rajtam, és Cunaján kívül?
Hogy tudok egy tömb-be parancsokat dobálni, értékek helyett?
Csak,hogy ne legyen ilyen hosszú a programom: (ez még hosszabb lesz...)
import time
import RPi.GPIO as GPIO
GPIO.cleanup()
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
channel = [17,18,22,27]
GPIO.setup(channel, GPIO.OUT)
time.sleep(0.5)
x=1
while True:
print "0"
GPIO.output(17, GPIO.LOW)
GPIO.output(18, GPIO.LOW)
GPIO.output(27, GPIO.LOW)
GPIO.output(22, GPIO.LOW)
time.sleep(0.5)
print "1"
GPIO.output(17, GPIO.HIGH)
GPIO.output(18, GPIO.LOW)
GPIO.output(27, GPIO.LOW)
GPIO.output(22, GPIO.LOW)
time.sleep(0.5)
print "2"
GPIO.output(17, GPIO.LOW)
GPIO.output(18, GPIO.HIGH)
GPIO.output(27, GPIO.LOW)
GPIO.output(22, GPIO.LOW)
time.sleep(0.5)
print "3"
GPIO.output(17, GPIO.HIGH)
GPIO.output(18, GPIO.HIGH)
GPIO.output(27, GPIO.LOW)
GPIO.output(22, GPIO.LOW)
time.sleep(0.5)
print "4"
GPIO.output(17, GPIO.LOW)
GPIO.output(18, GPIO.LOW)
GPIO.output(27, GPIO.HIGH)
GPIO.output(22, GPIO.LOW)
time.sleep(0.5)
print "5"
GPIO.output(17, GPIO.HIGH)
GPIO.output(18, GPIO.LOW)
GPIO.output(27, GPIO.HIGH)
GPIO.output(22, GPIO.LOW)
time.sleep(0.5)
print "6"
GPIO.output(17, GPIO.LOW)
GPIO.output(18, GPIO.HIGH)
GPIO.output(27, GPIO.HIGH)
GPIO.output(22, GPIO.LOW)
time.sleep(0.5)
print "7"
GPIO.output(17, GPIO.HIGH)
GPIO.output(18, GPIO.HIGH)
GPIO.output(27, GPIO.HIGH)
GPIO.output(22, GPIO.LOW)
time.sleep(0.5)
print "8"
GPIO.output(17, GPIO.LOW)
GPIO.output(18, GPIO.LOW)
GPIO.output(27, GPIO.LOW)
GPIO.output(22, GPIO.HIGH)
time.sleep(0.5)
print "9"
GPIO.output(17, GPIO.HIGH)
GPIO.output(18, GPIO.LOW)
GPIO.output(27, GPIO.LOW)
GPIO.output(22, GPIO.HIGH)
print "clean"
time.sleep(0.5)
GPIO.cleanup()Ezt a 4 sort:
GPIO.output(17, GPIO.LOW)
GPIO.output(18, GPIO.LOW)
GPIO.output(27, GPIO.LOW)
GPIO.output(22, GPIO.LOW)
time.sleep(0.5)
belerakni egy kis tömbbem és 4 sor helyett, csak egy tömb nvevet kellene meghívnom, sokkal jobb lenne. ötlet?[ Szerkesztve ]
"Neked is pörög az agyad a szarokon, amíg a mosoly a szádra kanyarodik."