Simple library for LED blinking.
Dependents: roam_v2 finalV1 finalV1 finalv2 ... more
Blinker.cpp
00001 #include "Blinker.h" 00002 #include "mbed.h" 00003 00004 Blinker::Blinker(PinName pin):myled(pin) { 00005 myled = 0; 00006 i = 0; 00007 N = 0; 00008 period = 0; 00009 } 00010 00011 void Blinker::blink(int n, float t) { 00012 finished = false; 00013 almostFinished = false; 00014 i = 0; 00015 if (i < n) { 00016 myled = 1; 00017 timeout.attach(this, &Blinker::turnLedOff, t/2); 00018 N = n; 00019 period = t; 00020 i++; 00021 if (i < N) { 00022 ticker.attach(this, &Blinker::turnLedOn, t); 00023 } else { 00024 almostFinished = true; 00025 } 00026 } else { 00027 finished = true; 00028 } 00029 } 00030 00031 void Blinker::turnLedOff() { 00032 myled = 0; 00033 if (almostFinished) { 00034 timeout.attach(this, &Blinker::done, period/2); 00035 } 00036 } 00037 00038 void Blinker::turnLedOn() { 00039 myled = 1; 00040 timeout.attach(this, &Blinker::turnLedOff, period/2); 00041 if (++i >= N) { 00042 ticker.detach(); 00043 almostFinished = true; 00044 } 00045 } 00046 void Blinker::done() { 00047 finished = true; 00048 } 00049 00050 bool Blinker::isFinished() { 00051 return finished; 00052 }
Generated on Sun Jul 17 2022 00:05:30 by 1.7.2