![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
button (push to on switch) interfacing
main.cpp@0:61788d2c2807, 2015-04-17 (annotated)
- Committer:
- kumaresh
- Date:
- Fri Apr 17 12:55:30 2015 +0000
- Revision:
- 0:61788d2c2807
button (push to on switch) interfacing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kumaresh | 0:61788d2c2807 | 1 | #include "mbed.h" |
kumaresh | 0:61788d2c2807 | 2 | |
kumaresh | 0:61788d2c2807 | 3 | DigitalIn mybutton(USER_BUTTON); // user switch available in ST32 nucleo boards |
kumaresh | 0:61788d2c2807 | 4 | DigitalIn sw1(PC_13); // refer UM1724 ST nucleo User manual for pin details |
kumaresh | 0:61788d2c2807 | 5 | DigitalOut myled(LED1); |
kumaresh | 0:61788d2c2807 | 6 | |
kumaresh | 0:61788d2c2807 | 7 | int main() { |
kumaresh | 0:61788d2c2807 | 8 | while(1) { |
kumaresh | 0:61788d2c2807 | 9 | if (sw1 == 0) { // or you can use mybutton |
kumaresh | 0:61788d2c2807 | 10 | myled = !myled; // Toggle the LED state |
kumaresh | 0:61788d2c2807 | 11 | wait(0.2); // 200 ms |
kumaresh | 0:61788d2c2807 | 12 | } |
kumaresh | 0:61788d2c2807 | 13 | } |
kumaresh | 0:61788d2c2807 | 14 | } |
kumaresh | 0:61788d2c2807 | 15 |