![](/media/cache/profiles/3f4243a6f681f2920ac3e95a63517274.50x50_q85.jpg)
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.
Revision 12:8f420e390452, committed 2012-09-05
- Comitter:
- eqon
- Date:
- Wed Sep 05 07:27:16 2012 +0000
- Parent:
- 11:e23a7ac024c6
- Commit message:
- Publish v1
Changed in this revision
LEDout.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r e23a7ac024c6 -r 8f420e390452 LEDout.h --- a/LEDout.h Wed Sep 05 07:18:29 2012 +0000 +++ b/LEDout.h Wed Sep 05 07:27:16 2012 +0000 @@ -1,116 +1,115 @@ -/* LEDout.h */ - -#ifndef LEDOUT_H -#define LEDOUT_H -#include "mbed.h" - -/**Library to show error code with MBED leds. -@file LEDout.h -@code -#include "mbed.h" -#include "LEDout.h" -int main() -{ - LEDout led; - led.blink(15,20);//Blink code 15, 20times, //noblocking, so code can continue - for(int k=0; k<10; k++){ - printf("printing while blinking ;) \n"); - wait(1); - } - wait(2); - led.blinks(1,3);//blocking, code 1, 3 blinks, code will not continue until blinks done - led.blinkSet(2,3);//blocking, code stops here, blinks will continue blinking - return 0; -} -@endcode -*/ - - -/** Library to show error code with MBED leds. -* -*/ -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 blink - * @param cmd 1-15 - * @param cnt how many times to blink - * @param dur blink interval default 0.2sec - */ - - 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); - - - } - /** Blocking process blink - * @param cmd 1-15 - * @param cnt how many times to blink - * @param dur blink interval default 0.2sec - */ - 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); - } - } - /** Blocking process and end with loop - * @param cmd 1-15 - * @param cnt how many times to blink - * @param dur blink interval default 0.2sec - */ - 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; - } - } -}; -#endif/* LEDOUT_H */ +/* LEDout.h */ +#ifndef LEDOUT_H +#define LEDOUT_H +#include "mbed.h" + +/**Library to show error code with MBED leds. +@file LEDout.h +@code +#include "mbed.h" +#include "LEDout.h" +int main() +{ + LEDout led; + led.blink(15,20);//Blink code 15, 20times, //noblocking, so code can continue + for(int k=0; k<10; k++){ + printf("printing while blinking ;) \n"); + wait(1); + } + wait(2); + led.blinks(1,3);//blocking, code 1, 3 blinks, code will not continue until blinks done + led.blinkSet(2,3);//blocking, code stops here, blinks will continue blinking + return 0; +} +@endcode +*/ + + +/** Library to show error code with MBED leds. +* +*/ +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 blink + * @param cmd 1-15 + * @param cnt how many times to blink + * @param dur blink interval default 0.2sec + */ + + 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); + + + } + /** Blocking process blink + * @param cmd 1-15 + * @param cnt how many times to blink + * @param dur blink interval default 0.2sec + */ + 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); + } + } + /** Blocking process and end with loop + * @param cmd 1-15 + * @param cnt how many times to blink + * @param dur blink interval default 0.2sec + */ + 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; + } + } +}; +#endif/* LEDOUT_H */