rpi-experiments/main.py

35 lines
786 B
Python
Raw Normal View History

2018-04-04 08:39:59 +00:00
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import time
2018-04-04 21:40:10 +00:00
def buttonEventHandler(value):
print "buton event!"
if value is 0:
GPIO.output(24, True)
print('Button Pressed...')
else:
GPIO.output(24, False)
print('Button Released...')
2018-04-04 08:39:59 +00:00
2018-04-04 21:40:10 +00:00
def main():
print "Let's do this!"
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.OUT)
#GPIO.add_event_detect(23, GPIO.FALLING)
#GPIO.add_event_callback(23, buttonEventHandler)
try:
while True:
GPIO.wait_for_edge(23, GPIO.BOTH)
buttonEventHandler(GPIO.input(23))
except KeyboardInterrupt as e:
GPIO.cleanup()
raise
if __name__== "__main__":
main()