Lab 3 part1
Dependencies: mbed
Fork of Ticker_Example by
main.cpp@0:14eb5da7a9a3, 2013-02-19 (annotated)
- Committer:
- mbed_official
- Date:
- Tue Feb 19 15:58:42 2013 +0000
- Revision:
- 0:14eb5da7a9a3
- Child:
- 1:0515b0bc6ee1
First commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:14eb5da7a9a3 | 1 | #include "mbed.h" |
mbed_official | 0:14eb5da7a9a3 | 2 | |
mbed_official | 0:14eb5da7a9a3 | 3 | // A class for flip()-ing a DigitalOut |
mbed_official | 0:14eb5da7a9a3 | 4 | class Flipper { |
mbed_official | 0:14eb5da7a9a3 | 5 | public: |
mbed_official | 0:14eb5da7a9a3 | 6 | Flipper(PinName pin) : _pin(pin) { |
mbed_official | 0:14eb5da7a9a3 | 7 | _pin = 0; |
mbed_official | 0:14eb5da7a9a3 | 8 | } |
mbed_official | 0:14eb5da7a9a3 | 9 | void flip() { |
mbed_official | 0:14eb5da7a9a3 | 10 | _pin = !_pin; |
mbed_official | 0:14eb5da7a9a3 | 11 | } |
mbed_official | 0:14eb5da7a9a3 | 12 | private: |
mbed_official | 0:14eb5da7a9a3 | 13 | DigitalOut _pin; |
mbed_official | 0:14eb5da7a9a3 | 14 | }; |
mbed_official | 0:14eb5da7a9a3 | 15 | |
mbed_official | 0:14eb5da7a9a3 | 16 | DigitalOut led1(LED1); |
mbed_official | 0:14eb5da7a9a3 | 17 | Flipper f(LED2); |
mbed_official | 0:14eb5da7a9a3 | 18 | Ticker t; |
mbed_official | 0:14eb5da7a9a3 | 19 | |
mbed_official | 0:14eb5da7a9a3 | 20 | int main() { |
mbed_official | 0:14eb5da7a9a3 | 21 | t.attach(&f, &Flipper::flip, 2.0); // the address of the object, member function, and interval |
mbed_official | 0:14eb5da7a9a3 | 22 | |
mbed_official | 0:14eb5da7a9a3 | 23 | // spin in a main loop. flipper will interrupt it to call flip |
mbed_official | 0:14eb5da7a9a3 | 24 | while(1) { |
mbed_official | 0:14eb5da7a9a3 | 25 | led1 = !led1; |
mbed_official | 0:14eb5da7a9a3 | 26 | wait(0.2); |
mbed_official | 0:14eb5da7a9a3 | 27 | } |
mbed_official | 0:14eb5da7a9a3 | 28 | } |