Simple library for LED blinking.

Dependents:   roam_v2 finalV1 finalV1 finalv2 ... more

Committer:
tbjazic
Date:
Sat Dec 10 14:39:42 2016 +0000
Revision:
3:286a364f952f
Parent:
2:190915d53c0b
Child:
4:abcdbfe38247
wait() functions removed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tbjazic 0:c9a302c4bed9 1 #ifndef MBED_BLINKER_H_TB
tbjazic 0:c9a302c4bed9 2 #define MBED_BLINKER_H_TB
tbjazic 0:c9a302c4bed9 3
tbjazic 0:c9a302c4bed9 4 #include "mbed.h"
tbjazic 0:c9a302c4bed9 5
tbjazic 2:190915d53c0b 6 /** Simple class for learning development of libraries. The main task
tbjazic 2:190915d53c0b 7 * is to blink (flash) a LED connected to a specified pin N times.
tbjazic 2:190915d53c0b 8 * Each blink should last 0.5 seconds by default, or some other time
tbjazic 2:190915d53c0b 9 * that user can set.
tbjazic 1:ea5bb72717cc 10 *
tbjazic 1:ea5bb72717cc 11 * Author: TVZ Mechatronics Team
tbjazic 1:ea5bb72717cc 12 *
tbjazic 1:ea5bb72717cc 13 * Example of use:
tbjazic 1:ea5bb72717cc 14 * @code
tbjazic 1:ea5bb72717cc 15 * #include "mbed.h"
tbjazic 1:ea5bb72717cc 16 * #include "Blinker.h"
tbjazic 1:ea5bb72717cc 17 *
tbjazic 1:ea5bb72717cc 18 * int main() {
tbjazic 2:190915d53c0b 19 * Blinker myBlinker(LED3);
tbjazic 2:190915d53c0b 20 * myBlinker.blink(10);
tbjazic 1:ea5bb72717cc 21 * wait(2);
tbjazic 2:190915d53c0b 22 * myBlinker.blink(5, 1);
tbjazic 1:ea5bb72717cc 23 * }
tbjazic 1:ea5bb72717cc 24 * @endcode
tbjazic 1:ea5bb72717cc 25 */
tbjazic 0:c9a302c4bed9 26 class Blinker {
tbjazic 3:286a364f952f 27
tbjazic 0:c9a302c4bed9 28 public:
tbjazic 3:286a364f952f 29
tbjazic 2:190915d53c0b 30 /** Constructor receives a pin name that LED is connected to. */
tbjazic 0:c9a302c4bed9 31 Blinker(PinName pin);
tbjazic 3:286a364f952f 32
tbjazic 2:190915d53c0b 33 /** Function recevies number of blinks (flashes) and a time of duration of each blink. */
tbjazic 2:190915d53c0b 34 void blink(int n, float t = 0.5);
tbjazic 3:286a364f952f 35 /** Checks if the blinking is finished.
tbjazic 3:286a364f952f 36 * @returns true if the complete process is finished, false otherwise.
tbjazic 3:286a364f952f 37 */
tbjazic 3:286a364f952f 38 bool isFinished();
tbjazic 3:286a364f952f 39
tbjazic 3:286a364f952f 40 private:
tbjazic 3:286a364f952f 41
tbjazic 3:286a364f952f 42 DigitalOut myled;
tbjazic 3:286a364f952f 43 int i, N;
tbjazic 3:286a364f952f 44 float period;
tbjazic 3:286a364f952f 45 Ticker ticker;
tbjazic 3:286a364f952f 46 Timeout timeout;
tbjazic 3:286a364f952f 47 bool finished, almostFinished;
tbjazic 3:286a364f952f 48 void turnLedOff();
tbjazic 3:286a364f952f 49 void turnLedOn();
tbjazic 3:286a364f952f 50 void done();
tbjazic 0:c9a302c4bed9 51 };
tbjazic 0:c9a302c4bed9 52
tbjazic 0:c9a302c4bed9 53 #endif