Created
August 28, 2023 18:04
-
-
Save k5njm/d3446b4000b6224f3fdfba02317898f3 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
import RPi.GPIO as GPIO | |
import datetime | |
def my_callback(channel): | |
if GPIO.input(channel) == GPIO.HIGH: | |
print('\n▼ at ' + str(datetime.datetime.now())) | |
else: | |
print('\n ▲ at ' + str(datetime.datetime.now())) | |
try: | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP) | |
GPIO.add_event_detect(17, GPIO.BOTH, callback=my_callback) | |
message = input('\nPress any key to exit.\n') | |
finally: | |
GPIO.cleanup() | |
print("Goodbye!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment