Vishal Kotcherlakota
/
event_source
A simple program that triggers a GPIO rise/fall event when data arrives on the virtual COM port via USB.
main.cpp@0:a46083c93e2b, 2015-06-17 (annotated)
- Committer:
- dishbreak
- Date:
- Wed Jun 17 22:47:01 2015 +0000
- Revision:
- 0:a46083c93e2b
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dishbreak | 0:a46083c93e2b | 1 | #include "mbed.h" |
dishbreak | 0:a46083c93e2b | 2 | |
dishbreak | 0:a46083c93e2b | 3 | InterruptIn button(p28); |
dishbreak | 0:a46083c93e2b | 4 | DigitalOut led(LED1); |
dishbreak | 0:a46083c93e2b | 5 | DigitalOut flash(LED4); |
dishbreak | 0:a46083c93e2b | 6 | DigitalOut sigPin(p18); |
dishbreak | 0:a46083c93e2b | 7 | Serial pc(USBTX, USBRX); |
dishbreak | 0:a46083c93e2b | 8 | |
dishbreak | 0:a46083c93e2b | 9 | void led_on() { |
dishbreak | 0:a46083c93e2b | 10 | led = !led; |
dishbreak | 0:a46083c93e2b | 11 | } |
dishbreak | 0:a46083c93e2b | 12 | |
dishbreak | 0:a46083c93e2b | 13 | void led_off() { |
dishbreak | 0:a46083c93e2b | 14 | led = 0; |
dishbreak | 0:a46083c93e2b | 15 | } |
dishbreak | 0:a46083c93e2b | 16 | |
dishbreak | 0:a46083c93e2b | 17 | void on_pc_rcv() { |
dishbreak | 0:a46083c93e2b | 18 | pc.getc(); |
dishbreak | 0:a46083c93e2b | 19 | led = 1; |
dishbreak | 0:a46083c93e2b | 20 | sigPin = 1; |
dishbreak | 0:a46083c93e2b | 21 | wait(0.25); |
dishbreak | 0:a46083c93e2b | 22 | sigPin = 0; |
dishbreak | 0:a46083c93e2b | 23 | led = 0; |
dishbreak | 0:a46083c93e2b | 24 | } |
dishbreak | 0:a46083c93e2b | 25 | |
dishbreak | 0:a46083c93e2b | 26 | int main() { |
dishbreak | 0:a46083c93e2b | 27 | pc.attach(&on_pc_rcv); |
dishbreak | 0:a46083c93e2b | 28 | button.rise(&led_on); |
dishbreak | 0:a46083c93e2b | 29 | button.fall(&led_off); |
dishbreak | 0:a46083c93e2b | 30 | while(1) { // wait around, interrupts will interrupt this! |
dishbreak | 0:a46083c93e2b | 31 | flash = !flash; |
dishbreak | 0:a46083c93e2b | 32 | wait(0.25); |
dishbreak | 0:a46083c93e2b | 33 | } |
dishbreak | 0:a46083c93e2b | 34 | } |