Skip to content

Instantly share code, notes, and snippets.

@wimpunk
Last active July 30, 2020 19:26
Show Gist options
  • Save wimpunk/5f55a5b44fb761212708c29bc0d31317 to your computer and use it in GitHub Desktop.
Save wimpunk/5f55a5b44fb761212708c29bc0d31317 to your computer and use it in GitHub Desktop.
#!/bin/python
#
# laatste versie op https://git.io/JJ2YJ
# setup:
# - GND naar de - op het bord
# - kortste poot LED naar - lijn
# - langste poot LED naar gemeenschappelijke rij (bvb lijn 27)
# - weerstand ene poot op lijn 27 andere op zelfde lijn als GPIO 21 (lijn 21)
#
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
#GPIO.setwarnings(False)
LED = 21
ledState = False
GPIO.setup(LED, GPIO.OUT)
try:
while True:
ledState = not ledState
GPIO.output(LED, ledState)
time.sleep(0.5)
except:
print("some error")
finally:
GPIO.cleanup()
ledState = True
#!/bin/python
#
# laatste versie kan je vinden op https://git.io/JJ2Ye
#
# setup:
# - LED zoals in flikker: GPIO21 - weerstand - LED - 0V
# - DRUKKNOP in rij 35
# - een kant naar +
# - diagonale kant naar GPIO 20
# - + naar 5V of 3.3V
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
#GPIO.setwarnings(False)
# led aangesloten aan pin 21, cfr flikker
# drukknop aangesloten aan pin 20, direct naar de 5V
LED = 21
INPUT_PIN = 20
# LED initieren als uit
ledState = False
GPIO.setup(LED, GPIO.OUT)
# de INPUT configureren met een interne PULL DOWN configuratie.
# Door een pulldown of een pull up te gebruiken wordt een ingang
# niet "zwevend".
GPIO.setup(INPUT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
# we lezen op voorhand al eens uit wat er op de ingang staat
if GPIO.input(INPUT_PIN):
print('Input was HIGH')
else:
print('Input was LOW')
try:
while True:
print('We wachten twee seconden')
channel = GPIO.wait_for_edge(INPUT_PIN, GPIO.RISING, timeout=2000)
if channel is None:
print('Er werd niets gedrukt, timeout trad op')
else:
ledState = not ledState
GPIO.output(LED, ledState)
print('Edge detected on channel', channel)
time.sleep(0.5)
except Exception as e:
print("Er was een fout:")
print(e)
finally:
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment