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