Download NHK English news podcast automatically. This application requires mpod mother board. See also http://mbed.org/users/geodenx/notebook/mpod/
Dependencies: BlinkLed HTTPClient EthernetInterface FatFileSystemCpp MSCFileSystem mbed-rtos mbed
Download NHK English news podcast automatically. This application requires mpod mother board. See also http://mbed.org/users/geodenx/notebook/mpod/
BlinkLed.cpp@0:1855a008f28e, 2012-08-16 (annotated)
- Committer:
- togayan
- Date:
- Thu Aug 16 15:49:19 2012 +0000
- Revision:
- 0:1855a008f28e
- Child:
- 2:0da3a4508b46
First revision of mpod_nhk_english.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
togayan | 0:1855a008f28e | 1 | #include "BlinkLed.h" |
togayan | 0:1855a008f28e | 2 | |
togayan | 0:1855a008f28e | 3 | BlinkLed::BlinkLed(PinName pin, uint32_t millisecWait, const char* name) : |
togayan | 0:1855a008f28e | 4 | led(pin, name), |
togayan | 0:1855a008f28e | 5 | millisecWait(millisecWait), |
togayan | 0:1855a008f28e | 6 | thread(0) |
togayan | 0:1855a008f28e | 7 | { |
togayan | 0:1855a008f28e | 8 | } |
togayan | 0:1855a008f28e | 9 | |
togayan | 0:1855a008f28e | 10 | BlinkLed::~BlinkLed() |
togayan | 0:1855a008f28e | 11 | { |
togayan | 0:1855a008f28e | 12 | } |
togayan | 0:1855a008f28e | 13 | |
togayan | 0:1855a008f28e | 14 | void BlinkLed::startBlink() |
togayan | 0:1855a008f28e | 15 | { |
togayan | 0:1855a008f28e | 16 | if(thread == 0) |
togayan | 0:1855a008f28e | 17 | { |
togayan | 0:1855a008f28e | 18 | thread = new Thread(blink, this); |
togayan | 0:1855a008f28e | 19 | } |
togayan | 0:1855a008f28e | 20 | } |
togayan | 0:1855a008f28e | 21 | |
togayan | 0:1855a008f28e | 22 | void BlinkLed::finishBlink() |
togayan | 0:1855a008f28e | 23 | { |
togayan | 0:1855a008f28e | 24 | if(thread != 0) |
togayan | 0:1855a008f28e | 25 | { |
togayan | 0:1855a008f28e | 26 | thread->terminate(); |
togayan | 0:1855a008f28e | 27 | thread = 0; |
togayan | 0:1855a008f28e | 28 | led = 0.0; |
togayan | 0:1855a008f28e | 29 | } |
togayan | 0:1855a008f28e | 30 | } |
togayan | 0:1855a008f28e | 31 | |
togayan | 0:1855a008f28e | 32 | void BlinkLed::blink(void const *argument) |
togayan | 0:1855a008f28e | 33 | { |
togayan | 0:1855a008f28e | 34 | BlinkLed* blinkLed = (BlinkLed*)argument; |
togayan | 0:1855a008f28e | 35 | |
togayan | 0:1855a008f28e | 36 | int up = 1; |
togayan | 0:1855a008f28e | 37 | float brightness = 0.0; |
togayan | 0:1855a008f28e | 38 | while (1) { |
togayan | 0:1855a008f28e | 39 | if (up == 1 && brightness < 1.0) { |
togayan | 0:1855a008f28e | 40 | ; |
togayan | 0:1855a008f28e | 41 | } else if (up == 1 && brightness >= 1.0) { |
togayan | 0:1855a008f28e | 42 | up = 0; |
togayan | 0:1855a008f28e | 43 | } else if (up == 0 && brightness > 0) { |
togayan | 0:1855a008f28e | 44 | ; |
togayan | 0:1855a008f28e | 45 | } else if (up == 0 && brightness <= 0.0) { |
togayan | 0:1855a008f28e | 46 | up = 1; |
togayan | 0:1855a008f28e | 47 | } else { |
togayan | 0:1855a008f28e | 48 | error("LED PWM error\n"); |
togayan | 0:1855a008f28e | 49 | } |
togayan | 0:1855a008f28e | 50 | |
togayan | 0:1855a008f28e | 51 | if (up == 1) { |
togayan | 0:1855a008f28e | 52 | brightness += 0.01; |
togayan | 0:1855a008f28e | 53 | } else { |
togayan | 0:1855a008f28e | 54 | brightness -= 0.01; |
togayan | 0:1855a008f28e | 55 | } |
togayan | 0:1855a008f28e | 56 | blinkLed->led = brightness; |
togayan | 0:1855a008f28e | 57 | |
togayan | 0:1855a008f28e | 58 | Thread::wait(blinkLed->millisecWait); |
togayan | 0:1855a008f28e | 59 | } |
togayan | 0:1855a008f28e | 60 | } |