Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of Ticker_Example by
main.cpp@1:0515b0bc6ee1, 2015-10-06 (annotated)
- Committer:
- ldeng31
- Date:
- Tue Oct 06 19:28:06 2015 +0000
- Revision:
- 1:0515b0bc6ee1
- Parent:
- 0:14eb5da7a9a3
Lab3 part 1 Ticker;
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 | |
| ldeng31 | 1:0515b0bc6ee1 | 16 | Flipper f_1(LED1); |
| ldeng31 | 1:0515b0bc6ee1 | 17 | Flipper f_2(LED2); |
| ldeng31 | 1:0515b0bc6ee1 | 18 | Flipper f_3(LED3); |
| ldeng31 | 1:0515b0bc6ee1 | 19 | Flipper f_4(LED4); |
| ldeng31 | 1:0515b0bc6ee1 | 20 | |
| ldeng31 | 1:0515b0bc6ee1 | 21 | Ticker t_1; |
| ldeng31 | 1:0515b0bc6ee1 | 22 | Ticker t_2; |
| ldeng31 | 1:0515b0bc6ee1 | 23 | Ticker t_3; |
| ldeng31 | 1:0515b0bc6ee1 | 24 | Ticker t_4; |
| mbed_official | 0:14eb5da7a9a3 | 25 | |
| mbed_official | 0:14eb5da7a9a3 | 26 | int main() { |
| ldeng31 | 1:0515b0bc6ee1 | 27 | t_1.attach(&f_1, &Flipper::flip, 1.0); |
| ldeng31 | 1:0515b0bc6ee1 | 28 | t_2.attach(&f_2, &Flipper::flip, 2.0); // the address of the object, member function, and interval |
| ldeng31 | 1:0515b0bc6ee1 | 29 | t_3.attach(&f_3,&Flipper::flip,3.0); |
| ldeng31 | 1:0515b0bc6ee1 | 30 | t_4.attach(&f_4, &Flipper::flip, 4.0); |
| mbed_official | 0:14eb5da7a9a3 | 31 | // spin in a main loop. flipper will interrupt it to call flip |
| ldeng31 | 1:0515b0bc6ee1 | 32 | while(1) |
| ldeng31 | 1:0515b0bc6ee1 | 33 | { |
| ldeng31 | 1:0515b0bc6ee1 | 34 | } |
| mbed_official | 0:14eb5da7a9a3 | 35 | } |
