Simple library for LED blinking.

Dependents:   roam_v2 finalV1 finalV1 finalv2 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Blinker.h Source File

Blinker.h

00001 #ifndef MBED_BLINKER_H_TB
00002 #define MBED_BLINKER_H_TB
00003 
00004 #include "mbed.h"
00005 
00006 /** Simple class for learning development of libraries. The main task
00007  *  is to blink (flash) a LED connected to a specified pin N times. 
00008  * Each blink should last 0.5 seconds by default, or some other time
00009  * that user can set.
00010  * 
00011  * Author: TVZ Mechatronics Team
00012  *
00013  * Example of use:
00014  * @code
00015  * #include "mbed.h"
00016  * #include "Blinker.h"
00017  *
00018  * int main() {
00019  *    Blinker myBlinker(LED3);
00020  *    myBlinker.blink(10);
00021  *    while(!myBlinker.isFinished()) {
00022  *        // do something else...
00023  *    }
00024  *    myBlinker.blink(5, 1);
00025  *    while(!myBlinker.isFinished()) {
00026  *        // do something else...
00027  *    }
00028  * }
00029  * @endcode
00030  */
00031 class Blinker {
00032 
00033 public:
00034 
00035     /** Constructor receives a pin name that LED is connected to. */
00036     Blinker(PinName pin);
00037 
00038     /** Function recevies number of blinks (flashes) and a time of duration of each blink. */
00039     void blink(int n, float t = 0.5);
00040     
00041     /** Checks if the blinking is finished. 
00042      * @returns true if the complete process is finished, false otherwise.
00043      */
00044     bool isFinished();
00045 
00046 private:
00047 
00048     DigitalOut myled;
00049     int i, N;
00050     float period;
00051     Ticker ticker;
00052     Timeout timeout;
00053     bool finished, almostFinished;
00054     void turnLedOff();
00055     void turnLedOn();
00056     void done();
00057 };
00058 
00059 #endif