You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
916 B
51 lines
916 B
2 years ago
|
#! /usr/bin/python3
|
||
|
|
||
|
import RPi.GPIO as GPIO
|
||
|
from time import sleep
|
||
|
|
||
2 years ago
|
__PIN__ = 23 # GPIO Pin, den wir nutzen
|
||
|
__WAIT__ = 0.5 # Warten für 0,5 Sekunden
|
||
2 years ago
|
|
||
|
GPIO.setwarnings(False)
|
||
2 years ago
|
|
||
|
# benutze Broadcom Pin Nummerierung
|
||
2 years ago
|
GPIO.setmode(GPIO.BCM)
|
||
2 years ago
|
|
||
|
# Pin 23 als Output schalten.
|
||
2 years ago
|
GPIO.setup(__PIN__,GPIO.OUT)
|
||
|
|
||
2 years ago
|
#Zustand der LED setzen
|
||
|
def setLED(state):
|
||
|
|
||
|
GPIO.output(__PIN__,state)
|
||
|
|
||
|
# Dauerschleife, die die LED im Wechsel ein- und ausschaltet.
|
||
|
# Wird gestoppt mit CTRL-C
|
||
|
def blinkloop():
|
||
|
try:
|
||
|
while True:
|
||
|
|
||
|
# Pin auf HIGH setzen schaltet die LED ein
|
||
|
setLED(GPIO.HIGH)
|
||
|
print('LED ein')
|
||
|
|
||
|
sleep(__WAIT__)
|
||
2 years ago
|
|
||
2 years ago
|
# Pin auf LOW setzen schaltet die LED aus
|
||
|
setLED(GPIO.LOW)
|
||
|
print('LED aus')
|
||
|
sleep(__WAIT__)
|
||
|
except KeyboardInterrupt:
|
||
|
pass
|
||
|
finally:
|
||
|
# Zum schluss immer die LED ausschalten.
|
||
|
setLED(GPIO.LOW)
|
||
2 years ago
|
|
||
2 years ago
|
if __name__ =='__main__':
|
||
|
blinkloop()
|
||
|
GPIO.cleanup(__PIN__)
|
||
2 years ago
|
|
||
|
|
||
|
|
||
|
|