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.
Fork of mbed_blinky by
Revision 3:ccd87cea3adc, committed 2015-11-25
- Comitter:
- nehap
- Date:
- Wed Nov 25 09:35:52 2015 +0000
- Parent:
- 2:dc82c1187f3a
- Commit message:
- file;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r dc82c1187f3a -r ccd87cea3adc main.cpp
--- a/main.cpp Wed Dec 03 12:47:42 2014 +0000
+++ b/main.cpp Wed Nov 25 09:35:52 2015 +0000
@@ -1,42 +1,27 @@
#include "mbed.h"
-
-DigitalOut myled1(LED1);
-DigitalOut myled2(LED2);
-DigitalOut myled3(LED3);
-DigitalOut myled4(LED4);
-
-
+
+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 led1(LED3);
+
int main() {
- while(1) {
- myled1 = 1;
- myled2 = 0;
- myled3 = 0;
- myled4 = 0;
- wait(0.2);
- myled1 = 0;
- myled2 = 1;
- myled3 = 0;
- myled4 = 0;
- wait(0.1);
- myled1 = 0;
- myled2 = 0;
- myled3 = 1;
- myled4 = 0;
- wait(0.1);
- myled1 = 0;
- myled2 = 0;
- myled3 = 0;
- myled4 = 1;
- wait(0.2);
- myled1 = 0;
- myled2 = 0;
- myled3 = 1;
- myled4 = 0;
- wait(0.1);
- myled1 = 0;
- myled2 = 1;
- myled3 = 0;
- myled4 = 0;
- wait(0.1);
- }
+ led.flash(5);
+ led.flash(2);
+ led1.flash(7);
}
