Commit 2e45abdd authored by plaasio's avatar plaasio 👷🏽

Update btns.py

parent 1351f80e
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
def no_callback(channel):
print("no Button was pushed!")
def down_callback(channel):
print("down Button was pushed!")
def up_callback(channel):
print("up Button was pushed!")
def yes_callback(channel):
print("yes Button was pushed!")
GPIO.setwarnings(True) # Ignore warning for now
GPIO.setwarnings(False) # Ignore warning for now
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Set pin 22 to be an input pin and set initial value to be pulled low (off)
GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Set pin 23 to be an input pin and set initial value to be pulled low (off)
GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Set pin 24 to be an input pin and set initial value to be pulled low (off)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Set pin 26 to be an input pin and set initial value to be pulled low (off)
GPIO.add_event_detect(13,GPIO.RISING,callback=no_callback) # Setup event on pin 22 rising edge
GPIO.add_event_detect(15,GPIO.RISING,callback=down_callback) # Setup event on pin 23 rising edge
GPIO.add_event_detect(16,GPIO.RISING,callback=up_callback) # Setup event on pin 24 rising edge
GPIO.add_event_detect(18,GPIO.RISING,callback=yes_callback) # Setup event on pin 26 rising edge
while True: # Run forever
if GPIO.input(13) == GPIO.HIGH:
print("no")
if GPIO.input(15) == GPIO.HIGH:
print("down")
if GPIO.input(16) == GPIO.HIGH:
print("up")
if GPIO.input(18) == GPIO.HIGH:
print("yes")
#message = input("Press enter to quit\n\n") # Run until someone presses enter
#GPIO.cleanup()
#GPIO.cleanup()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment