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.

BlinkLed.h

Committer:
togayan
Date:
2012-12-24
Revision:
2:1d0c09c1a8b4
Parent:
0:a55a3351317d

File content as of revision 2:1d0c09c1a8b4:

/* BlinkLed.h */
#ifndef BLINKLED_H_
#define BLINKLED_H_

#include "mbed.h"
#include "rtos.h"

/** LED which blinks automatically with RTOS
*/
class BlinkLed
{
public:
    /** Constructor
     */
    BlinkLed(PinName pin, float dutyChangeStep);
    
    /** Destructor
     */
    ~BlinkLed();
    
    /** Start biinking
     */
    void startBlink();
    
    /** Finish biinking
     */
    void finishBlink();
    
    /** Check biinking
     */
    bool isBlinking();
      
private:
    /** Copy constructor
     *  Disable because it is only declaration
     */
    BlinkLed(const BlinkLed&);
    
    /** Copy assignment operators
     *  Disable because it is only declaration
     */
    BlinkLed& operator=(const BlinkLed&);
    
    /** Function for blinking
     *  This function will be bind to new thread
     */
    static void blink(void const *argument);
    
    /** Target Led
     */
    PwmOut led;
    
    /** Duty ratio step of changing every 20ms
     */
    float dutyChangeStep;
    
    /** Flag of pause
     */
    bool pause;
    
    /** Pointer to thread for blinking
     */
    Thread* thread;
};

#endif /* BLINKLED_H_ */