Library to show error code with MBED leds. Decimal error code 1-15 can be set
This library can show Your error code (integer 1-15) on MBED Leds.
Diff: LEDout.h
- Revision:
- 0:3e7de538b366
- Child:
- 1:bef84bec3049
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LEDout.h Wed Sep 05 06:16:31 2012 +0000 @@ -0,0 +1,74 @@ +#include "mbed.h" +class LEDout : public BusOut +{ + public: + /** Create a LEDout object + * + */ + + LEDout():BusOut(LED1,LED2,LED3,LED4) { + _cmd=0; + _dur=0; + _blankwait=2; //sec + // printf("Ledout init\n"); + } + /** Non-blocking process + * @param cmd 1-15 + @param cnt how many times to blink + */ + void blink(int cmd,int cnt, float dur=0.2) {// parallel process + _cmd=0; + _dur=0; + _cmd=cmd; + _dur=dur*1000*1000; + _blinkcnt=0;//reset + _blinkamount=cnt*2;//on/off + // printf("Blink start cmd %d dur %f blinkcnt %d amount %d cnt %d\n",_cmd,_dur,_blinkcnt,_blinkamount, cnt); + _ticker2.attach_us(this,&LEDout::blinktick,_dur); + // printf("Blink start cmd %d dur %f blinkcnt %d amount %d cnt %d\n",_cmd,_dur,_blinkcnt,_blinkamount, cnt); + + + } + void blinks(int cmd,int cnt, float dur =0.2) {// blocking + for (int k=1; k<=cnt; k++) { + LEDout::write(cmd);//ON + wait(dur); + LEDout::write(0);//OFF + wait(dur); + } + } + void blinkSet(int cmd,int cnt, float dur =0.2) {// blocking and stopping + + while (1) { + blinks( cmd, cnt, dur); + wait(_blankwait); // blank space + } + } + protected: + Timeout _timeout; + Ticker _ticker2; + int _blinkcnt; + int _blinkamount; + int _cmd; // bit command + float _blankwait; + float _dur; + + + void blinktick(void) {// ticker function + + // printf("blink\n"); + if (LEDout::read()==_cmd)//command + LEDout::write(0); + else + LEDout::write(_cmd); + + _blinkcnt++; + + if (_blinkamount==NULL or !_blinkamount)return; + + if (_blinkcnt==_blinkamount) { + _ticker2.detach(); + return; + } + } +};