Simple Debouncing library and sample code.
Dependencies: DebouncedIn mbed
main.cpp@1:3f6f29315707, 2016-06-12 (annotated)
- Committer:
- SIT2016
- Date:
- Sun Jun 12 09:17:20 2016 +0000
- Revision:
- 1:3f6f29315707
- Parent:
- 0:4b63a4c5ed47
- Child:
- 2:e7f390d1e86c
Debouncing switch code with and without the library usage.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SIT2016 | 0:4b63a4c5ed47 | 1 | #include "mbed.h" |
SIT2016 | 0:4b63a4c5ed47 | 2 | #include "DebouncedIn.h" |
SIT2016 | 0:4b63a4c5ed47 | 3 | |
SIT2016 | 1:3f6f29315707 | 4 | DigitalOut led(LED1); //red led |
SIT2016 | 0:4b63a4c5ed47 | 5 | DebouncedIn button(PTC9); //switch |
SIT2016 | 0:4b63a4c5ed47 | 6 | |
SIT2016 | 0:4b63a4c5ed47 | 7 | int main() { |
SIT2016 | 0:4b63a4c5ed47 | 8 | while(1) { |
SIT2016 | 1:3f6f29315707 | 9 | //using library directly |
SIT2016 | 1:3f6f29315707 | 10 | /*if (button.rising()){ //execute only if rising edge detected on the button. |
SIT2016 | 0:4b63a4c5ed47 | 11 | led = !led; |
SIT2016 | 1:3f6f29315707 | 12 | }*/ |
SIT2016 | 1:3f6f29315707 | 13 | |
SIT2016 | 1:3f6f29315707 | 14 | //without library |
SIT2016 | 1:3f6f29315707 | 15 | if(button == 0) { //detecting press |
SIT2016 | 1:3f6f29315707 | 16 | led = !led; |
SIT2016 | 1:3f6f29315707 | 17 | while(button==0); //empty while to wait while switch is pressed. hence toggling only once. |
SIT2016 | 0:4b63a4c5ed47 | 18 | } |
SIT2016 | 0:4b63a4c5ed47 | 19 | } |
SIT2016 | 0:4b63a4c5ed47 | 20 | } |
SIT2016 | 0:4b63a4c5ed47 | 21 |