Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vousmeevoyez/d9b1ab78ff8dca91d480c9d363db9b79 to your computer and use it in GitHub Desktop.
Save vousmeevoyez/d9b1ab78ff8dca91d480c9d363db9b79 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# encoding: utf-8
import time
try:
import importlib.util
importlib.util.find_spec("RPi.GPIO")
import RPi.GPIO as GPIO
except ImportError:
# handle failed import
import FakeRPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Button to GPIO16
GPIO.setup(18, GPIO.OUT) # LED to GPIO18
try:
while True:
button_state = GPIO.input(16)
if button_state is False:
GPIO.output(18, True)
print("Button Pressed...")
time.sleep(0.2)
else:
GPIO.output(18, False)
except:
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment