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.
LEDout.h
- Committer:
- eqon
- Date:
- 2012-09-05
- Revision:
- 1:bef84bec3049
- Parent:
- 0:3e7de538b366
- Child:
- 2:947917aff1fa
File content as of revision 1:bef84bec3049:
#include "mbed.h"
/**
*@file LEDout.h
*@brief Library to show error code with MBED leds.
*@author Egon
*@date 9/5/2012
*/
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
* @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
* @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;
}
}
};