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:55ffb01ac6ca, 2016-11-30 (annotated)
- Committer:
- akshay28
- Date:
- Wed Nov 30 08:33:05 2016 +0000
- Revision:
- 0:55ffb01ac6ca
bvb;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
akshay28 | 0:55ffb01ac6ca | 1 | #include "mbed.h" |
akshay28 | 0:55ffb01ac6ca | 2 | |
akshay28 | 0:55ffb01ac6ca | 3 | class Flasher { |
akshay28 | 0:55ffb01ac6ca | 4 | public: |
akshay28 | 0:55ffb01ac6ca | 5 | Flasher(PinName pin) : _pin(pin) { // _pin(pin) means pass pin to the DigitalOut constructor |
akshay28 | 0:55ffb01ac6ca | 6 | _pin = 0; // default the output to 0 |
akshay28 | 0:55ffb01ac6ca | 7 | } |
akshay28 | 0:55ffb01ac6ca | 8 | |
akshay28 | 0:55ffb01ac6ca | 9 | void flash(int n) { |
akshay28 | 0:55ffb01ac6ca | 10 | for(int i=0; i<n*2; i++) { |
akshay28 | 0:55ffb01ac6ca | 11 | _pin = !_pin; |
akshay28 | 0:55ffb01ac6ca | 12 | wait(0.2); |
akshay28 | 0:55ffb01ac6ca | 13 | } |
akshay28 | 0:55ffb01ac6ca | 14 | } |
akshay28 | 0:55ffb01ac6ca | 15 | |
akshay28 | 0:55ffb01ac6ca | 16 | private: |
akshay28 | 0:55ffb01ac6ca | 17 | DigitalOut _pin; |
akshay28 | 0:55ffb01ac6ca | 18 | }; |
akshay28 | 0:55ffb01ac6ca | 19 | |
akshay28 | 0:55ffb01ac6ca | 20 | Flasher led(LED2); |
akshay28 | 0:55ffb01ac6ca | 21 | Flasher out(p6); |
akshay28 | 0:55ffb01ac6ca | 22 | |
akshay28 | 0:55ffb01ac6ca | 23 | int main() { |
akshay28 | 0:55ffb01ac6ca | 24 | led.flash(5); |
akshay28 | 0:55ffb01ac6ca | 25 | led.flash(2); |
akshay28 | 0:55ffb01ac6ca | 26 | out.flash(10); |
akshay28 | 0:55ffb01ac6ca | 27 | } |