Simple library for LED blinking.
Dependents: roam_v2 finalV1 finalV1 finalv2 ... more
Blinker.h@4:abcdbfe38247, 2016-12-15 (annotated)
- Committer:
- tbjazic
- Date:
- Thu Dec 15 10:56:25 2016 +0000
- Revision:
- 4:abcdbfe38247
- Parent:
- 3:286a364f952f
Insignificant.
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:abcdbfe38247 | 21 | * while(!myBlinker.isFinished()) { |
tbjazic | 4:abcdbfe38247 | 22 | * // do something else... |
tbjazic | 4:abcdbfe38247 | 23 | * } |
tbjazic | 2:190915d53c0b | 24 | * myBlinker.blink(5, 1); |
tbjazic | 4:abcdbfe38247 | 25 | * while(!myBlinker.isFinished()) { |
tbjazic | 4:abcdbfe38247 | 26 | * // do something else... |
tbjazic | 4:abcdbfe38247 | 27 | * } |
tbjazic | 1:ea5bb72717cc | 28 | * } |
tbjazic | 1:ea5bb72717cc | 29 | * @endcode |
tbjazic | 1:ea5bb72717cc | 30 | */ |
tbjazic | 0:c9a302c4bed9 | 31 | class Blinker { |
tbjazic | 3:286a364f952f | 32 | |
tbjazic | 0:c9a302c4bed9 | 33 | public: |
tbjazic | 3:286a364f952f | 34 | |
tbjazic | 2:190915d53c0b | 35 | /** Constructor receives a pin name that LED is connected to. */ |
tbjazic | 0:c9a302c4bed9 | 36 | Blinker(PinName pin); |
tbjazic | 3:286a364f952f | 37 | |
tbjazic | 2:190915d53c0b | 38 | /** Function recevies number of blinks (flashes) and a time of duration of each blink. */ |
tbjazic | 2:190915d53c0b | 39 | void blink(int n, float t = 0.5); |
tbjazic | 4:abcdbfe38247 | 40 | |
tbjazic | 3:286a364f952f | 41 | /** Checks if the blinking is finished. |
tbjazic | 3:286a364f952f | 42 | * @returns true if the complete process is finished, false otherwise. |
tbjazic | 3:286a364f952f | 43 | */ |
tbjazic | 3:286a364f952f | 44 | bool isFinished(); |
tbjazic | 3:286a364f952f | 45 | |
tbjazic | 3:286a364f952f | 46 | private: |
tbjazic | 3:286a364f952f | 47 | |
tbjazic | 3:286a364f952f | 48 | DigitalOut myled; |
tbjazic | 3:286a364f952f | 49 | int i, N; |
tbjazic | 3:286a364f952f | 50 | float period; |
tbjazic | 3:286a364f952f | 51 | Ticker ticker; |
tbjazic | 3:286a364f952f | 52 | Timeout timeout; |
tbjazic | 3:286a364f952f | 53 | bool finished, almostFinished; |
tbjazic | 3:286a364f952f | 54 | void turnLedOff(); |
tbjazic | 3:286a364f952f | 55 | void turnLedOn(); |
tbjazic | 3:286a364f952f | 56 | void done(); |
tbjazic | 0:c9a302c4bed9 | 57 | }; |
tbjazic | 0:c9a302c4bed9 | 58 | |
tbjazic | 0:c9a302c4bed9 | 59 | #endif |