-
Notifications
You must be signed in to change notification settings - Fork 0
/
StatusLED.h
54 lines (45 loc) · 1.21 KB
/
StatusLED.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef STATUS_LED_H
#define STATUS_LED_H
#include <stdint.h>
class StatusLED
{
public:
/*
* pin: Pin number of the LED. Must be initialized with pinMode.
* shortBlinkTime: (milliseconds) "on" period of bits that are 0.
* longBlinkTime: (milliseconds) "on" period of bits that are 1.
* blinkPause: (milliseconds) "off" period between bits.
* pause: (milliseconds) pause between blink sequences.
*/
StatusLED(int pin, unsigned long shortBlinkTime,
unsigned long longBlinkTime, unsigned long blinkPause,
unsigned long pause, bool inverted=false);
/*
* Use default blink periods
*/
StatusLED(int pin, bool inverted=false);
/*
* Set status and number of bits in status.
* e.g. status = 0b00001010, bitCount = 5 will set the sequence to be
* short long short long short
*/
void setStatus(uint8_t status, uint8_t bitCount);
/*
* must be called periodically
*/
void update();
private:
const int pin;
const bool inverted;
const unsigned long shortBlinkTime;
const unsigned long longBlinkTime;
const unsigned long blinkPause;
const unsigned long pause;
uint8_t bitfield;
uint8_t indexMod;
uint8_t currentIndex;
unsigned long time;
void reset();
void setOutput(bool val);
};
#endif