Engduino  3.1.0
A fun device for learning coding
EngduinoLEDs.h
Go to the documentation of this file.
1 
14 #ifndef __ENGDUINOLEDS_H__
15 #define __ENGDUINOLEDS_H__
16 
17 #include <Arduino.h>
18 #include <Engduino.h>
19 
20 enum colour {
21  RED,
22  GREEN,
23  BLUE,
24  YELLOW,
25  MAGENTA,
26  CYAN,
27  WHITE,
28  OFF
29 };
30 
31 #define MAX_BRIGHTNESS 0x0F
32 
33 // Needed to ensure correct linkage between C++ and C linkage of ISR
34 extern "C" void TIMER4_COMPA_vect(void) __attribute__ ((signal));
35 
37 {
38  private:
39  /*
40  * The xSet variables contain the values actually set by the user. RGB
41  * values run from 0-16 in each channel
42  */
43  uint8_t RSet[16];
44  uint8_t GSet[16];
45  uint8_t BSet[16];
46 
47  /*
48  * The xAccum and xDisp variables contain values used in the PWM
49  * implementation. The Accum variables are counter variables that
50  * increment at each time point by an amount equal to the brightness
51  * given to the channel (0-16). When the counter ticks over, the
52  * corresponding Disp bit is set, otherwise it is unset. Each
53  * tick, the calculated Disp values are sent to the LED drivers
54  */
55  volatile uint8_t RAccum[16];
56  volatile uint8_t GAccum[16];
57  volatile uint8_t BAccum[16];
58 
59  volatile uint8_t RDisp[16];
60  volatile uint8_t GDisp[16];
61  volatile uint8_t BDisp[16];
62 
63  void _setLED(uint8_t LEDidx, colour c, uint8_t brightness);
64  void _setLED(uint8_t LEDidx, uint8_t r, uint8_t g, uint8_t b);
65 
66  public:
67  EngduinoLEDsClass();
68  void begin(); // Default
69  void end();
70 
71  void setLED(uint8_t LEDNumber, colour c);
72  void setLED(uint8_t LEDNumber, colour c, uint8_t brightness);
73  void setLED(uint8_t LEDNumber, uint8_t r, uint8_t g, uint8_t b);
74 
75  void setAll(colour c);
76  void setAll(colour c, uint8_t brightness);
77  void setAll(uint8_t r, uint8_t g, uint8_t b);
78 
79  void setLEDs(colour c[16]);
80  void setLEDs(colour colour[16], uint8_t brightness[16]);
81  void setLEDs(uint8_t r[16], uint8_t g[16], uint8_t b[16]);
82  void setLEDs(uint8_t rgb[3][16]);
83  void setLEDs(uint8_t rgb[16][3]);
84 
85  /*
86  * The ISR needs access to the private variables, so we declare it
87  * a friend of the class
88  */
89  friend void TIMER4_COMPA_vect();
90 };
91 
92 
93 extern EngduinoLEDsClass EngduinoLEDs;
94 
95 #endif
96 
Definition: EngduinoLEDs.h:36