gpio_inputs_-_button_led_control_using_an_interrupt
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
gpio_inputs_-_button_led_control_using_an_interrupt [2016/08/09 22:58] – walkeradmin | gpio_inputs_-_button_led_control_using_an_interrupt [2016/08/09 23:04] – walkeradmin | ||
---|---|---|---|
Line 2: | Line 2: | ||
\\ | \\ | ||
\\ | \\ | ||
- | blah blah | + | The previous example of using a button to light an LED, everything worked fine, but our processor was at 100%, this needs fixing, so in this example instead of constantly polling and setting GPIO pins, we are using a interrupt where by we do nothing until a button is actually pressed. |
\\ | \\ | ||
+ | \\ | ||
+ | Create a new file in the normal way ( you can download the python file {{ : | ||
+ | \\ | ||
+ | sudo nano LED-Button-i.py | ||
\\ | \\ | ||
#import modules | #import modules | ||
- | import RPi.GPIO as GPIO # This imports the GPIO libarary | + | import RPi.GPIO as GPIO # This imports the GPIO library |
- | import time # This imports the time libarary | + | import time # This imports the time library |
# These libraries are built in to Raspbian. | # These libraries are built in to Raspbian. | ||
| | ||
Line 26: | Line 30: | ||
GPIO.output(12, | GPIO.output(12, | ||
| | ||
- | | + | # this is where we setup the GPIO input to use the event buttonPressed that was |
- | # to use the event buttonPressed that was | + | # defined previously. bouncetime is a simple |
- | # defined previously. bouncetime is a simp$ | + | GPIO.add_event_detect(11, |
- | # switch debouncer in mS. | + | |
| | ||
GPIO.setup(12, | GPIO.setup(12, |