Created
March 27, 2020 04:34
-
-
Save vousmeevoyez/d9b1ab78ff8dca91d480c9d363db9b79 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
#!/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