Last active
July 16, 2017 09:53
-
-
Save bennuttall/85f431916a1ab1c5e7fdaa36c5bfd26d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import RPi.GPIO as GPIO | |
global lampe1 | |
global lampe2 | |
global lampe3 | |
global lampe4 | |
global lampe5 | |
global lampe6 | |
lampe1 = 0 | |
lampe2 = 0 | |
lampe3 = 0 | |
lampe4 = 0 | |
lampe5 = 0 | |
lampe6 = 0 | |
GPIO.setmode(GPIO.BCM) | |
#THESE ARE THE LEDS | |
#Lampe = The Lights | |
#LampeTaste = small LED ring around the Button to signal which Light is on | |
#Pins 5, 6, 12, 14, 15, 17, 18, 22, 23, 24, 25, 27 set output | |
GPIO.setup(5, GPIO.OUT) #LampeTaste4 | |
GPIO.setup(6, GPIO.OUT) #LampeTaste5 | |
GPIO.setup(12, GPIO.OUT) #LampeTaste6 | |
GPIO.setup(13, GPIO.OUT) #Lampe1 | |
GPIO.setup(19, GPIO.OUT) #Lampe2 | |
GPIO.setup(16, GPIO.OUT) #Lampe3 | |
GPIO.setup(26, GPIO.OUT) #Lampe4 | |
GPIO.setup(21, GPIO.OUT) #Lampe6 | |
GPIO.setup(23, GPIO.OUT) #LampeTaste1 | |
GPIO.setup(24, GPIO.OUT) #LampeTaste2 | |
GPIO.setup(25, GPIO.OUT) #LampeTaste3 | |
GPIO.setup(20, GPIO.OUT) #Lampe5 | |
GPIO.output(5, GPIO.HIGH) | |
GPIO.output(6, GPIO.HIGH) | |
GPIO.output(12, GPIO.HIGH) | |
GPIO.output(13, GPIO.HIGH) | |
GPIO.output(19, GPIO.HIGH) | |
GPIO.output(16, GPIO.HIGH) | |
GPIO.output(26, GPIO.HIGH) | |
GPIO.output(21, GPIO.HIGH) | |
GPIO.output(23, GPIO.HIGH) | |
GPIO.output(24, GPIO.HIGH) | |
GPIO.output(25, GPIO.HIGH) | |
GPIO.output(20, GPIO.HIGH) | |
#THESE ARE THE BUTTONS | |
#Pins 14, 15, 17, 18, 22, 27 auf input setzen | |
GPIO.setup(14, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Taste1 | |
GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Taste2 | |
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Taste3 | |
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Taste4 | |
GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Taste5 | |
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Taste6 | |
#Programm | |
while 1: | |
#Button check----------------------------- | |
if GPIO.input(14) == GPIO.LOW: | |
if lampe1 == 0: | |
lampe1 = 1 | |
else: | |
lampe1 = 0 | |
while GPIO.input(14) == GPIO.LOW: | |
time.sleep(0.1) | |
if GPIO.input(17) == GPIO.LOW: | |
if lampe3 == 0: | |
lampe3 = 1 | |
else: | |
lampe3 = 0 | |
while GPIO.input(17) == GPIO.LOW: | |
time.sleep(0.1) | |
if GPIO.input(15) == GPIO.LOW: | |
if lampe2 == 0: | |
lampe2 = 1 | |
else: | |
lampe2 = 0 | |
while GPIO.input(15) == GPIO.LOW: | |
time.sleep(0.1) | |
if GPIO.input(27) == GPIO.LOW: | |
if lampe5 == 0: | |
lampe5 = 1 | |
else: | |
lampe5 = 0 | |
while GPIO.input(27) == GPIO.LOW: | |
time.sleep(0.1) | |
if GPIO.input(22) == GPIO.LOW: | |
if lampe6 == 0: | |
lampe6 = 1 | |
else: | |
lampe6 = 0 | |
while GPIO.input(22) == GPIO.LOW: | |
time.sleep(0.1) | |
if GPIO.input(18) == GPIO.LOW: | |
if lampe4 == 0: | |
lampe4 = 1 | |
else: | |
lampe4 = 0 | |
while GPIO.input(18) == GPIO.LOW: | |
time.sleep(0.1) | |
#-------------------------------------------- | |
#SET LIGHTS ON AND OFF | |
#Lichter einschalten/ausschalten------------- | |
if lampe1 == 0: | |
GPIO.output(13, GPIO.HIGH) | |
GPIO.output(23, GPIO.HIGH) | |
else: | |
GPIO.output(13, GPIO.LOW) | |
GPIO.output(23, GPIO.LOW) | |
if lampe2 == 0: | |
GPIO.output(19, GPIO.HIGH) | |
GPIO.output(24, GPIO.HIGH) | |
else: | |
GPIO.output(19, GPIO.LOW) | |
GPIO.output(24, GPIO.LOW) | |
if lampe3 == 0: | |
GPIO.output(16, GPIO.HIGH) | |
GPIO.output(25, GPIO.HIGH) | |
else: | |
GPIO.output(16, GPIO.LOW) | |
GPIO.output(25, GPIO.LOW) | |
if lampe4 == 0: | |
GPIO.output(26, GPIO.HIGH) | |
GPIO.output(5, GPIO.HIGH) | |
else: | |
GPIO.output(26, GPIO.LOW) | |
GPIO.output(5, GPIO.LOW) | |
if lampe5 == 0: | |
GPIO.output(20, GPIO.HIGH) | |
GPIO.output(6, GPIO.HIGH) | |
else: | |
GPIO.output(20, GPIO.LOW) | |
GPIO.output(6, GPIO.LOW) | |
if lampe6 == 0: | |
GPIO.output(21, GPIO.HIGH) | |
GPIO.output(12, GPIO.HIGH) | |
else: | |
GPIO.output(21, GPIO.LOW) | |
GPIO.output(12, GPIO.LOW) | |
time.sleep(0.1) | |
#-------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gpiozero import LEDBoard, Button | |
from signal import pause | |
leds1 = LEDBoard(13,23) | |
leds2 = LEDBoard(19,24) | |
leds3 = LEDBoard(16,25) | |
leds4 = LEDBoard(26,5) | |
leds5 = LEDBoard(20,6) | |
leds6 = LEDBoard(21,12) | |
button1 = Button(14) | |
button2 = Button(15) | |
button3 = Button(17) | |
button4 = Button(18) | |
button5 = Button(27) | |
button6 = Button(22) | |
button1.when_pressed = leds1.toggle | |
button2.when_pressed = leds2.toggle | |
button3.when_pressed = leds3.toggle | |
button4.when_pressed = leds4.toggle | |
button5.when_pressed = leds5.toggle | |
button6.when_pressed = leds6.toggle | |
pause() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gpiozero import LEDBoard, ButtonBoard | |
from signal import pause | |
led_pins = ((13, 23), (19, 24), (16, 25), (26, 5), (20, 6), (21, 12)) | |
leds = LEDBoard(*(LEDBoard(a, b) for a, b in led_pins)) | |
buttons = ButtonBoard(14, 15, 17, 18, 27, 22) | |
for led, button in zip(leds, buttons): | |
button.when_pressed = led.toggle | |
pause() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment