RGBlink  1.0
an Arduino RGB-Led library
 All Classes Functions Variables
RGBlink.h
1 #ifndef RGBlink_h //Avoid including this lib twice
2 #define RGBlink_h
3 
4 #if defined(ARDUINO) && ARDUINO >= 100 //check if using Arduino or Wiring
5  #include "Arduino.h"
6 #else
7  #include "WProgram.h"
8 #endif
9 
10 #define hstep 60 // steps for each main color(cyan, magenta, yellow, green, red , blue), by default 60 => 360° colorspace
11 
16 typedef struct
17 {
18  uint8_t red;
19  uint8_t green;
20  uint8_t blue;
21 } RGB;
22 
27 typedef struct
28 {
29  uint16_t hue;
30  uint8_t sat;
31  uint8_t bri;
32 } HSB;
33 
34 const HSB red = {000 ,255,255};
35 const HSB green = {hstep*2,255,255};
36 const HSB blue = {hstep*4,255,255};
37 const HSB yellow = {hstep ,255,255};
38 
39 PROGMEM const prog_uint8_t dim_curve[256] = {
40  0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3,
41  3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4,
42  4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6,
43  6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
44  8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11,
45  11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15,
46  15, 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20,
47  20, 20, 21, 21, 22, 22, 22, 23, 23, 24, 24, 25, 25, 25, 26, 26,
48  27, 27, 28, 28, 29, 29, 30, 30, 31, 32, 32, 33, 33, 34, 35, 35,
49  36, 36, 37, 38, 38, 39, 40, 40, 41, 42, 43, 43, 44, 45, 46, 47,
50  48, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
51  63, 64, 65, 66, 68, 69, 70, 71, 73, 74, 75, 76, 78, 79, 81, 82,
52  83, 85, 86, 88, 90, 91, 93, 94, 96, 98, 99, 101, 103, 105, 107, 109,
53  110, 112, 114, 116, 118, 121, 123, 125, 127, 129, 132, 134, 136, 139, 141, 144,
54  146, 149, 151, 154, 157, 159, 162, 165, 168, 171, 174, 177, 180, 183, 186, 190,
55  193, 196, 200, 203, 207, 211, 214, 218, 222, 226, 230, 234, 238, 242, 248, 255
56 };
57 
63 class LED
64 {
65  public:
73  LED(uint8_t to_red_pin,uint8_t to_green_pin,uint8_t to_blue_pin);
82  LED(uint8_t to_red_pin,uint8_t to_green_pin,uint8_t to_blue_pin,bool to_inverted);
83 
88  void on();
93  void off();
94 
99  void update();
103  void initDefaults();
107  void writeRGB(RGB to_color);
112  void writeHSB(HSB to_color);
117  void setColor(HSB to_color);
124  void setBlink(uint16_t to_on_val, uint16_t to_off_val);
135  void setMode(uint8_t to_mode);
139  int getMode();
145  void flash(uint16_t to_on_val);
146  private:
147  uint8_t red_pin, green_pin, blue_pin; // used Arduino Pins
148  HSB color;
149  uint16_t blink_on, blink_off, flash_on;
150  bool isOn;
151  bool inverted; // invert the PWM values?
152 
153  uint8_t mode;
154 
155  unsigned long prevMillis; // store the last mills() for non-block blinking
156 };
157 
162 RGB HSBtoRGB(HSB from_color);
170 HSB mix(HSB color_1, HSB color_2, uint8_t step);
171 
172 #endif