Skip to content

Instantly share code, notes, and snippets.

@k5njm
Created August 28, 2023 18:04
Show Gist options
  • Save k5njm/d3446b4000b6224f3fdfba02317898f3 to your computer and use it in GitHub Desktop.
Save k5njm/d3446b4000b6224f3fdfba02317898f3 to your computer and use it in GitHub Desktop.
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