BlinkLed automatically. This library requires RTOS.

Dependents:   mpod_nhk_english mpod_picasa_photoframe mpod_nhk_english_spxml

This is a library that automatically blink LED

RTOS has been used. However, you do not need to be aware of the RTOS.

As with PwmOut, there are restrictions on the LED that you can use. See also PwmOut.

LEDを自動的に点滅させるライブラリです。

内部にRTOSを利用していますが、ユーザがそのことを意識する必要はありません。

使用できるLEDは、PwmOutと同様の制約があります。詳しくは、PwmOutを参照ください。

main.cpp

#include "mbed.h"
#include "BlinkLed.h"

BlinkLed led1(LED1, 0.02);
BlinkLed led2(LED2, 0.04);
BlinkLed led3(LED3, 0.06);
BlinkLed led4(LED4, 0.08);

int main()
{
    while(1) {
        led1.startBlink();
        Thread::wait(1000);

        led2.startBlink();
        Thread::wait(1000);

        led3.startBlink();
        Thread::wait(1000);

        led4.startBlink();
        Thread::wait(10000);

        led1.finishBlink();
        Thread::wait(1000);

        led2.finishBlink();
        Thread::wait(1000);

        led3.finishBlink();
        Thread::wait(1000);

        led4.finishBlink();
        Thread::wait(1000);
    }
}

Import library

Public Member Functions

  BlinkLed (PinName pin, float dutyChangeStep)
  Constructor.
  ~BlinkLed ()
  Destructor.
void  startBlink ()
  Start biinking.
void  finishBlink ()
  Finish biinking.
Committer:
togayan
Date:
Mon Dec 24 06:38:42 2012 +0000
Revision:
2:1d0c09c1a8b4
Parent:
0:a55a3351317d
Add "isBlinking()" method.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
togayan 0:a55a3351317d 1 /* BlinkLed.h */
togayan 0:a55a3351317d 2 #ifndef BLINKLED_H_
togayan 0:a55a3351317d 3 #define BLINKLED_H_
togayan 0:a55a3351317d 4
togayan 0:a55a3351317d 5 #include "mbed.h"
togayan 0:a55a3351317d 6 #include "rtos.h"
togayan 0:a55a3351317d 7
togayan 0:a55a3351317d 8 /** LED which blinks automatically with RTOS
togayan 0:a55a3351317d 9 */
togayan 0:a55a3351317d 10 class BlinkLed
togayan 0:a55a3351317d 11 {
togayan 0:a55a3351317d 12 public:
togayan 0:a55a3351317d 13 /** Constructor
togayan 0:a55a3351317d 14 */
togayan 0:a55a3351317d 15 BlinkLed(PinName pin, float dutyChangeStep);
togayan 0:a55a3351317d 16
togayan 0:a55a3351317d 17 /** Destructor
togayan 0:a55a3351317d 18 */
togayan 0:a55a3351317d 19 ~BlinkLed();
togayan 0:a55a3351317d 20
togayan 0:a55a3351317d 21 /** Start biinking
togayan 0:a55a3351317d 22 */
togayan 0:a55a3351317d 23 void startBlink();
togayan 0:a55a3351317d 24
togayan 0:a55a3351317d 25 /** Finish biinking
togayan 0:a55a3351317d 26 */
togayan 0:a55a3351317d 27 void finishBlink();
togayan 2:1d0c09c1a8b4 28
togayan 2:1d0c09c1a8b4 29 /** Check biinking
togayan 2:1d0c09c1a8b4 30 */
togayan 2:1d0c09c1a8b4 31 bool isBlinking();
togayan 0:a55a3351317d 32
togayan 0:a55a3351317d 33 private:
togayan 0:a55a3351317d 34 /** Copy constructor
togayan 0:a55a3351317d 35 * Disable because it is only declaration
togayan 0:a55a3351317d 36 */
togayan 0:a55a3351317d 37 BlinkLed(const BlinkLed&);
togayan 0:a55a3351317d 38
togayan 0:a55a3351317d 39 /** Copy assignment operators
togayan 0:a55a3351317d 40 * Disable because it is only declaration
togayan 0:a55a3351317d 41 */
togayan 0:a55a3351317d 42 BlinkLed& operator=(const BlinkLed&);
togayan 0:a55a3351317d 43
togayan 0:a55a3351317d 44 /** Function for blinking
togayan 0:a55a3351317d 45 * This function will be bind to new thread
togayan 0:a55a3351317d 46 */
togayan 0:a55a3351317d 47 static void blink(void const *argument);
togayan 0:a55a3351317d 48
togayan 0:a55a3351317d 49 /** Target Led
togayan 0:a55a3351317d 50 */
togayan 0:a55a3351317d 51 PwmOut led;
togayan 0:a55a3351317d 52
togayan 0:a55a3351317d 53 /** Duty ratio step of changing every 20ms
togayan 0:a55a3351317d 54 */
togayan 0:a55a3351317d 55 float dutyChangeStep;
togayan 0:a55a3351317d 56
togayan 0:a55a3351317d 57 /** Flag of pause
togayan 0:a55a3351317d 58 */
togayan 0:a55a3351317d 59 bool pause;
togayan 0:a55a3351317d 60
togayan 0:a55a3351317d 61 /** Pointer to thread for blinking
togayan 0:a55a3351317d 62 */
togayan 0:a55a3351317d 63 Thread* thread;
togayan 0:a55a3351317d 64 };
togayan 0:a55a3351317d 65
togayan 0:a55a3351317d 66 #endif /* BLINKLED_H_ */