Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 7:19da09fe546b, committed 2014-04-14
- Comitter:
- silverpanda
- Date:
- Mon Apr 14 03:04:28 2014 +0000
- Parent:
- 6:78a965b2d2df
- Commit message:
- with LED flashes
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LEDColors.cpp Mon Apr 14 03:04:28 2014 +0000 @@ -0,0 +1,59 @@ +#include "mbed.h" +#include "LEDColors.h" + +// constructor +LEDColors::LEDColors() +{ + // DigitalOut ledRed(LED_RED), ledBlue(LED_BLUE), ledGreen(LED_GREEN); + ledRed = new DigitalOut(LED_RED); + ledBlue = new DigitalOut(LED_BLUE); + ledGreen = new DigitalOut(LED_GREEN); + + // turn all three LEDs off + *ledRed = true; + redTimer = 0; + + *ledBlue = true; + blueTimer = 0; + + *ledGreen = true; + greenTimer = 0; +} +//----------------------------------------------------------------------------- + +void LEDColors::tick10ms() +{ + if(redTimer && !--redTimer) *ledRed = true; + if(blueTimer && !--blueTimer) *ledBlue = true; + if(greenTimer && !--greenTimer) *ledGreen = true; +} +//----------------------------------------------------------------------------- + +void LEDColors::flashRed(uint32_t duration) +{ + *ledRed = false; + redTimer = duration; +} +//----------------------------------------------------------------------------- + +void LEDColors::flashBlue(uint32_t duration) +{ + *ledBlue = false; + blueTimer = duration; +} +//----------------------------------------------------------------------------- + +void LEDColors::flashGreen(uint32_t duration) +{ + *ledGreen = false; + greenTimer = duration; +} +//----------------------------------------------------------------------------- + +void LEDColors::flashWhite(uint32_t duration) +{ + flashRed(duration); + flashBlue(duration); + flashGreen(duration); +} +//----------------------------------------------------------------------------- \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LEDColors.h Mon Apr 14 03:04:28 2014 +0000 @@ -0,0 +1,17 @@ +#ifndef ledcolors__h__ +#define ledcolors__h__ + +class LEDColors { +public: + LEDColors(); + void tick10ms(); + void flashRed(uint32_t); + void flashBlue(uint32_t); + void flashGreen(uint32_t); + void flashWhite(uint32_t); +private: + DigitalOut *ledRed, *ledBlue, *ledGreen; + uint32_t redTimer, blueTimer, greenTimer; +}; + +#endif \ No newline at end of file
--- a/main.cpp Mon Apr 14 01:53:10 2014 +0000 +++ b/main.cpp Mon Apr 14 03:04:28 2014 +0000 @@ -2,14 +2,18 @@ #include "mbed.h" #include "shell.h" +#include "LEDColors.h" Ticker *scanTicker; Shell *usbSerialShell; +LEDColors *ledColors; + bool scanUSBSerialRxFlag; -void setScanUSBSerialRxFlag() +void at10msTick() { scanUSBSerialRxFlag = true; + ledColors->tick10ms(); } //----------------------------------------------------------------------------- @@ -23,8 +27,10 @@ // start polling for characters scanTicker = new Ticker(); - scanTicker->attach(&setScanUSBSerialRxFlag, 0.01); + scanTicker->attach(&at10msTick, 0.01); scanUSBSerialRxFlag = false; + + ledColors = new LEDColors(); } //-----------------------------------------------------------------------------
--- a/shell.cpp Mon Apr 14 01:53:10 2014 +0000 +++ b/shell.cpp Mon Apr 14 03:04:28 2014 +0000 @@ -1,6 +1,9 @@ #include "mbed.h" +#include "LEDColors.h" #include "shell.h" +extern LEDColors *ledColors; + // create contructor Shell::Shell(uint32_t thisBaudRate) { @@ -33,10 +36,16 @@ // see if this is a semi colon or a carriage return // if so, give a new line cursor - if((character == ';') || (character == 13)) usbSerial->printf("\n> "); + if((character == ';') || (character == 13)) { + usbSerial->printf("\n> "); + ledColors->flashWhite(10); + } // if not, just print the character - else usbSerial->printf("%c", character); + else { + usbSerial->printf("%c", character); + ledColors->flashGreen(10); + } } } //-----------------------------------------------------------------------------