![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Grove Starter Kit for mbed - Button
main.cpp@1:f93ac9d8770c, 2015-02-24 (annotated)
- Committer:
- lingtien5846
- Date:
- Tue Feb 24 13:45:20 2015 +0000
- Revision:
- 1:f93ac9d8770c
- Parent:
- 0:c48d7e51d9c9
Update main.cpp
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lingtien5846 | 0:c48d7e51d9c9 | 1 | #include "mbed.h" |
lingtien5846 | 0:c48d7e51d9c9 | 2 | |
lingtien5846 | 1:f93ac9d8770c | 3 | DigitalOut led(LED1); |
lingtien5846 | 0:c48d7e51d9c9 | 4 | DigitalIn button(p21); |
lingtien5846 | 0:c48d7e51d9c9 | 5 | |
lingtien5846 | 1:f93ac9d8770c | 6 | int main() |
lingtien5846 | 1:f93ac9d8770c | 7 | { |
lingtien5846 | 0:c48d7e51d9c9 | 8 | while(1) { |
lingtien5846 | 1:f93ac9d8770c | 9 | wait(0.1); |
lingtien5846 | 0:c48d7e51d9c9 | 10 | if (button) { |
lingtien5846 | 1:f93ac9d8770c | 11 | led = 1; |
lingtien5846 | 1:f93ac9d8770c | 12 | } else { |
lingtien5846 | 1:f93ac9d8770c | 13 | led = 0; |
lingtien5846 | 0:c48d7e51d9c9 | 14 | } |
lingtien5846 | 1:f93ac9d8770c | 15 | wait(0.4); // simple debouncing |
lingtien5846 | 0:c48d7e51d9c9 | 16 | } |
lingtien5846 | 1:f93ac9d8770c | 17 | } |