Engduino v2.1
|
00001 /** 00002 * \defgroup EngduinoLEDs Driver for Engduino LEDS 00003 * 00004 * @{ 00005 */ 00006 00007 /** 00008 * \file 00009 * Engduino LED driver 00010 * \author 00011 * Engduino team: support@engduino.org 00012 */ 00013 00014 #ifndef __ENGDUINOLEDS_H__ 00015 #define __ENGDUINOLEDS_H__ 00016 00017 #include <Arduino.h> 00018 #include <Engduino.h> 00019 00020 enum colour { 00021 RED, 00022 GREEN, 00023 BLUE, 00024 YELLOW, 00025 MAGENTA, 00026 CYAN, 00027 WHITE, 00028 OFF 00029 }; 00030 00031 #define MAX_BRIGHTNESS 0x0F 00032 00033 // Needed to ensure correct linkage between C++ and C linkage of ISR 00034 extern "C" void TIMER4_COMPA_vect(void) __attribute__ ((signal)); 00035 00036 class EngduinoLEDsClass 00037 { 00038 private: 00039 /* 00040 * The xSet variables contain the values actually set by the user. RGB 00041 * values run from 0-16 in each channel 00042 */ 00043 uint8_t RSet[16]; 00044 uint8_t GSet[16]; 00045 uint8_t BSet[16]; 00046 00047 /* 00048 * The xAccum and xDisp variables contain values used in the PWM 00049 * implementation. The Accum variables are counter variables that 00050 * increment at each time point by an amount equal to the brightness 00051 * given to the channel (0-16). When the counter ticks over, the 00052 * corresponding Disp bit is set, otherwise it is unset. Each 00053 * tick, the calculated Disp values are sent to the LED drivers 00054 */ 00055 volatile uint8_t RAccum[16]; 00056 volatile uint8_t GAccum[16]; 00057 volatile uint8_t BAccum[16]; 00058 00059 volatile uint8_t RDisp[16]; 00060 volatile uint8_t GDisp[16]; 00061 volatile uint8_t BDisp[16]; 00062 00063 void _setLED(uint8_t LEDidx, colour c, uint8_t brightness); 00064 void _setLED(uint8_t LEDidx, uint8_t r, uint8_t g, uint8_t b); 00065 00066 public: 00067 EngduinoLEDsClass(); 00068 void begin(); // Default 00069 void end(); 00070 00071 void setLED(uint8_t LEDNumber, colour c); 00072 void setLED(uint8_t LEDNumber, colour c, uint8_t brightness); 00073 void setLED(uint8_t LEDNumber, uint8_t r, uint8_t g, uint8_t b); 00074 00075 void setAll(colour c); 00076 void setAll(colour c, uint8_t brightness); 00077 void setAll(uint8_t r, uint8_t g, uint8_t b); 00078 00079 void setLEDs(colour c[16]); 00080 void setLEDs(colour colour[16], uint8_t brightness[16]); 00081 void setLEDs(uint8_t r[16], uint8_t g[16], uint8_t b[16]); 00082 void setLEDs(uint8_t rgb[3][16]); 00083 void setLEDs(uint8_t rgb[16][3]); 00084 00085 /* 00086 * The ISR needs access to the private variables, so we declare it 00087 * a friend of the class 00088 */ 00089 friend void TIMER4_COMPA_vect(); 00090 }; 00091 00092 00093 extern EngduinoLEDsClass EngduinoLEDs; 00094 00095 #endif 00096 00097 /** @} */