asha pawar
/
HelloWorld
my own library
Fork of HelloWorld by
Revision 3:966b57ac5efc, committed 2015-11-25
- Comitter:
- ashapawar
- Date:
- Wed Nov 25 12:33:02 2015 +0000
- Parent:
- 2:d42b0e3fe08a
- Commit message:
- own library
Changed in this revision
diff -r d42b0e3fe08a -r 966b57ac5efc Flasher.cpp --- a/Flasher.cpp Wed Nov 25 09:46:48 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -#include "Flasher.h" -#include "mbed.h" - -Flasher::Flasher(PinName pin) : _pin(pin) { - _pin = 0; -} - -void Flasher::flash(int n) { - for(int i=0; i<n*2; i++) { - _pin = !_pin; - wait(0.2); - } -}
diff -r d42b0e3fe08a -r 966b57ac5efc Flasher.h --- a/Flasher.h Wed Nov 25 09:46:48 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -#ifndef MBED_FLASHER_H -#define MBED_FLASHER_H - -#include "mbed.h" - -class Flasher { -public: - Flasher(PinName pin); - void flash(int n); - -private: - DigitalOut _pin; -}; - -#endif
diff -r d42b0e3fe08a -r 966b57ac5efc main.cpp --- a/main.cpp Wed Nov 25 09:46:48 2015 +0000 +++ b/main.cpp Wed Nov 25 12:33:02 2015 +0000 @@ -1,10 +1,26 @@ #include "mbed.h" -#include "Flasher.h" +class Flasher { +public: + Flasher(PinName pin) : _pin(pin) { // _pin(pin) means pass pin to the DigitalOut constructor + _pin = 0; // default the output to 0 + } + + void flash(int n) { + for(int i=0; i<n*2; i++) { + _pin = !_pin; + wait(0.2); + } + } +private: + DigitalOut _pin; +}; Flasher led(LED2); +Flasher out(LED3); int main() { led.flash(5); led.flash(2); + out.flash(10); }