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:
Sat Sep 01 04:02:02 2012 +0000
Revision:
0:a55a3351317d
Child:
1:54071e781f77
1st revision of BlinkLed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
togayan 0:a55a3351317d 1 #include "BlinkLed.h"
togayan 0:a55a3351317d 2
togayan 0:a55a3351317d 3 BlinkLed::BlinkLed(PinName pin, float dutyChangeStep) :
togayan 0:a55a3351317d 4 led(pin),
togayan 0:a55a3351317d 5 dutyChangeStep(dutyChangeStep),
togayan 0:a55a3351317d 6 pause(true),
togayan 0:a55a3351317d 7 thread(0)
togayan 0:a55a3351317d 8 {
togayan 0:a55a3351317d 9 }
togayan 0:a55a3351317d 10
togayan 0:a55a3351317d 11 BlinkLed::~BlinkLed()
togayan 0:a55a3351317d 12 {
togayan 0:a55a3351317d 13 }
togayan 0:a55a3351317d 14
togayan 0:a55a3351317d 15 void BlinkLed::startBlink()
togayan 0:a55a3351317d 16 {
togayan 0:a55a3351317d 17 pause = false;
togayan 0:a55a3351317d 18 if(thread == 0)
togayan 0:a55a3351317d 19 {
togayan 0:a55a3351317d 20 thread = new Thread(blink, this, osPriorityNormal, 128, NULL);
togayan 0:a55a3351317d 21 }
togayan 0:a55a3351317d 22 }
togayan 0:a55a3351317d 23
togayan 0:a55a3351317d 24 void BlinkLed::finishBlink()
togayan 0:a55a3351317d 25 {
togayan 0:a55a3351317d 26 pause = true;
togayan 0:a55a3351317d 27 }
togayan 0:a55a3351317d 28
togayan 0:a55a3351317d 29 void BlinkLed::blink(void const *argument)
togayan 0:a55a3351317d 30 {
togayan 0:a55a3351317d 31 BlinkLed* self = (BlinkLed*)argument;
togayan 0:a55a3351317d 32
togayan 0:a55a3351317d 33 bool sign = false;
togayan 0:a55a3351317d 34 while (1)
togayan 0:a55a3351317d 35 {
togayan 0:a55a3351317d 36 if(self->pause)
togayan 0:a55a3351317d 37 {
togayan 0:a55a3351317d 38 self->led = 0.0F;
togayan 0:a55a3351317d 39 }
togayan 0:a55a3351317d 40 else
togayan 0:a55a3351317d 41 {
togayan 0:a55a3351317d 42 float brightness = self->led;
togayan 0:a55a3351317d 43 sign = (brightness <= 0.0F) ? true : (1.0F <= brightness) ? false : sign;
togayan 0:a55a3351317d 44 self->led = sign ? brightness + self->dutyChangeStep : brightness - self->dutyChangeStep;
togayan 0:a55a3351317d 45 }
togayan 0:a55a3351317d 46 Thread::wait(20);
togayan 0:a55a3351317d 47 }
togayan 0:a55a3351317d 48 }