Library to show error code with MBED leds. Decimal error code 1-15 can be set

Dependencies:   mbed

This library can show Your error code (integer 1-15) on MBED Leds.

Committer:
eqon
Date:
Wed Sep 05 06:39:22 2012 +0000
Revision:
1:bef84bec3049
Parent:
0:3e7de538b366
Child:
2:947917aff1fa
documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eqon 0:3e7de538b366 1 #include "mbed.h"
eqon 1:bef84bec3049 2
eqon 1:bef84bec3049 3 /**
eqon 1:bef84bec3049 4 *@file LEDout.h
eqon 1:bef84bec3049 5 *@brief Library to show error code with MBED leds.
eqon 1:bef84bec3049 6 *@author Egon
eqon 1:bef84bec3049 7 *@date 9/5/2012
eqon 1:bef84bec3049 8 */
eqon 0:3e7de538b366 9 class LEDout : public BusOut
eqon 0:3e7de538b366 10 {
eqon 1:bef84bec3049 11 public:
eqon 1:bef84bec3049 12 /**
eqon 1:bef84bec3049 13 *Create a LEDout object
eqon 1:bef84bec3049 14 */
eqon 0:3e7de538b366 15
eqon 0:3e7de538b366 16 LEDout():BusOut(LED1,LED2,LED3,LED4) {
eqon 0:3e7de538b366 17 _cmd=0;
eqon 0:3e7de538b366 18 _dur=0;
eqon 0:3e7de538b366 19 _blankwait=2; //sec
eqon 0:3e7de538b366 20 // printf("Ledout init\n");
eqon 0:3e7de538b366 21 }
eqon 1:bef84bec3049 22 /** Non-blocking process
eqon 1:bef84bec3049 23 * @param cmd 1-15
eqon 1:bef84bec3049 24 * @param cnt how many times to blink
eqon 1:bef84bec3049 25 * @param dur blink interval default 0.2sec
eqon 1:bef84bec3049 26 */
eqon 0:3e7de538b366 27 void blink(int cmd,int cnt, float dur=0.2) {// parallel process
eqon 0:3e7de538b366 28 _cmd=0;
eqon 0:3e7de538b366 29 _dur=0;
eqon 0:3e7de538b366 30 _cmd=cmd;
eqon 0:3e7de538b366 31 _dur=dur*1000*1000;
eqon 0:3e7de538b366 32 _blinkcnt=0;//reset
eqon 0:3e7de538b366 33 _blinkamount=cnt*2;//on/off
eqon 0:3e7de538b366 34 // printf("Blink start cmd %d dur %f blinkcnt %d amount %d cnt %d\n",_cmd,_dur,_blinkcnt,_blinkamount, cnt);
eqon 0:3e7de538b366 35 _ticker2.attach_us(this,&LEDout::blinktick,_dur);
eqon 0:3e7de538b366 36 // printf("Blink start cmd %d dur %f blinkcnt %d amount %d cnt %d\n",_cmd,_dur,_blinkcnt,_blinkamount, cnt);
eqon 0:3e7de538b366 37
eqon 0:3e7de538b366 38
eqon 0:3e7de538b366 39 }
eqon 1:bef84bec3049 40 /** blocking process
eqon 1:bef84bec3049 41 * @param cmd 1-15
eqon 1:bef84bec3049 42 * @param cnt how many times to blink
eqon 1:bef84bec3049 43 * @param dur blink interval default 0.2sec
eqon 1:bef84bec3049 44 */
eqon 0:3e7de538b366 45 void blinks(int cmd,int cnt, float dur =0.2) {// blocking
eqon 0:3e7de538b366 46 for (int k=1; k<=cnt; k++) {
eqon 0:3e7de538b366 47 LEDout::write(cmd);//ON
eqon 0:3e7de538b366 48 wait(dur);
eqon 0:3e7de538b366 49 LEDout::write(0);//OFF
eqon 0:3e7de538b366 50 wait(dur);
eqon 0:3e7de538b366 51 }
eqon 0:3e7de538b366 52 }
eqon 1:bef84bec3049 53 /** blocking process and end with loop
eqon 1:bef84bec3049 54 * @param cmd 1-15
eqon 1:bef84bec3049 55 * @param cnt how many times to blink
eqon 1:bef84bec3049 56 * @param dur blink interval default 0.2sec
eqon 1:bef84bec3049 57 */
eqon 0:3e7de538b366 58 void blinkSet(int cmd,int cnt, float dur =0.2) {// blocking and stopping
eqon 0:3e7de538b366 59
eqon 0:3e7de538b366 60 while (1) {
eqon 0:3e7de538b366 61 blinks( cmd, cnt, dur);
eqon 0:3e7de538b366 62 wait(_blankwait); // blank space
eqon 0:3e7de538b366 63 }
eqon 0:3e7de538b366 64 }
eqon 1:bef84bec3049 65 protected:
eqon 0:3e7de538b366 66 Timeout _timeout;
eqon 0:3e7de538b366 67 Ticker _ticker2;
eqon 0:3e7de538b366 68 int _blinkcnt;
eqon 0:3e7de538b366 69 int _blinkamount;
eqon 0:3e7de538b366 70 int _cmd; // bit command
eqon 0:3e7de538b366 71 float _blankwait;
eqon 0:3e7de538b366 72 float _dur;
eqon 1:bef84bec3049 73
eqon 1:bef84bec3049 74
eqon 0:3e7de538b366 75 void blinktick(void) {// ticker function
eqon 0:3e7de538b366 76
eqon 0:3e7de538b366 77 // printf("blink\n");
eqon 0:3e7de538b366 78 if (LEDout::read()==_cmd)//command
eqon 0:3e7de538b366 79 LEDout::write(0);
eqon 0:3e7de538b366 80 else
eqon 0:3e7de538b366 81 LEDout::write(_cmd);
eqon 0:3e7de538b366 82
eqon 0:3e7de538b366 83 _blinkcnt++;
eqon 0:3e7de538b366 84
eqon 0:3e7de538b366 85 if (_blinkamount==NULL or !_blinkamount)return;
eqon 0:3e7de538b366 86
eqon 0:3e7de538b366 87 if (_blinkcnt==_blinkamount) {
eqon 0:3e7de538b366 88 _ticker2.detach();
eqon 0:3e7de538b366 89 return;
eqon 0:3e7de538b366 90 }
eqon 0:3e7de538b366 91 }
eqon 0:3e7de538b366 92 };