28 lines
539 B
Python
Executable File
28 lines
539 B
Python
Executable File
#! env/bin/python3
|
|
|
|
import RPi.GPIO as GPIO
|
|
import time
|
|
|
|
if __name__ == "__main__":
|
|
|
|
# Setup for Hardware
|
|
PB_PIN = 22
|
|
|
|
GPIO.setmode(GPIO.BCM)
|
|
GPIO.setwarnings(False)
|
|
|
|
# Use the internal pull-down.
|
|
GPIO.setup(PB_PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
|
|
|
# Begin detected presses.
|
|
i = 0
|
|
try:
|
|
while True:
|
|
if GPIO.input(PB_PIN):
|
|
i += 1
|
|
print(f"Hi Gabby! Did you push the button? i = {i}")
|
|
time.sleep(0.1)
|
|
|
|
finally:
|
|
GPIO.cleanup()
|