Raspberry Pi GPIO
Eerste stappen met de GPIO-pinnen voor invoer/uitvoer, om te gebruiken met sensors en sturing.
Mijn leidraad hier is MakeZine: Tutorial Pi GPIO.
GPIO pinout
Schakelschema
Programma
Uiteindelijk programma pushbutton4.py
# pushbutton4.py # # 20150212 Paul Wiegmans # # Twee events , een callback import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP) def buttonpressed(channel): channel -= 22 # converteer pinnummer naar knop (23 -> 1, ..) print("Button %d pressed!" % channel) GPIO.add_event_detect(23, GPIO.RISING, callback=buttonpressed, bouncetime=10) GPIO.add_event_detect(24, GPIO.FALLING, callback=buttonpressed, bouncetime=10) while True: time.sleep(0.05) # just wasting time GPIO.remove_event_detect(23) GPIO.remove_event_detect(24) GPIO.cleanup()