diff --git a/examples/RGB LED Ring Small/LEDRingSmall_Demo/LEDRingSmall_Demo.ino b/examples/RGB LED Ring Small/LEDRingSmall_Demo/LEDRingSmall_Demo.ino new file mode 100644 index 0000000..4822bb0 --- /dev/null +++ b/examples/RGB LED Ring Small/LEDRingSmall_Demo/LEDRingSmall_Demo.ino @@ -0,0 +1,175 @@ +#include +#include "LEDRingSmall.h" + +/* + + Connections with Arduino UNO: + - -> GND + + -> 5V + SDA -> A4 + SCL -> A5 + INT -> A3 +*/ +const uint32_t fade1_table[24] = {0x8011EE, 0xA004DA, 0xBF00BF, 0xDA04A0, 0xEE1180, 0xFB255F, 0xFF4040, 0xFB5F25, 0xEE8011, 0xDAA004, 0xBFBF00, 0xA0DA04, 0x80EE11, 0x5FFB25, 0x40FF40, 0x25FB5F, 0x11EE80, 0x04DAA0, 0x00BFBF, 0x04A0DA, 0x1180EE, 0x255FFB, 0x4040FF, 0x5F25FB}; +const uint32_t fade2_table[24] = {0xFF0000, 0xFF0004, 0xFF0020, 0xFF006B, 0xFF00FF, 0x6B00FF, 0x2000FF, 0x0400FF, 0x0000FF, 0x0004FF, 0x0020FF, 0x006BFF, 0x00FFFF, 0x00FF6B, 0x00FF20, 0x00FF04, 0x00FF00, 0x04FF00, 0x20FF00, 0x6BFF00, 0xFFFF00, 0xFF6B00, 0xFF2000, 0xFF0400}; +static uint8_t j = 0; +static uint8_t i = 0; +static uint16_t tim = 0; +static uint8_t r = 5, g = 8, b = 20, rg = 40, br = 35, bg = 17; + +LEDRingSmall LEDRingSmall(0x60); + +void setup(void) { + + Wire.begin(); + Wire.setClock(400000); + + LEDRingSmall.LEDRingSmall_Reset(); + delay(20); + + LEDRingSmall.LEDRingSmall_Configuration(0x01); //Normal operation + LEDRingSmall.LEDRingSmall_PWMFrequencyEnable(1); + LEDRingSmall.LEDRingSmall_SpreadSpectrum(0b0010110); + LEDRingSmall.LEDRingSmall_GlobalCurrent(0x10); + LEDRingSmall.LEDRingSmall_SetScaling(0xFF); + LEDRingSmall.LEDRingSmall_PWM_MODE(); + + + +} + +void loop() { + LEDRingSmall.LEDRingSmall_GlobalCurrent(0x10); + LEDRingSmall.LEDRingSmall_PWM_MODE(); + + for (i = 0; i < 24; i++) { + LEDRingSmall.LEDRingSmall_Set_RED(i, 0xff); + delay(30); + } + + for (i = 0; i < 24; i++) { + LEDRingSmall.LEDRingSmall_Set_RED(i, 0); + LEDRingSmall.LEDRingSmall_Set_GREEN(i, 0xff); + delay(30); + } + + for (i = 0; i < 24; i++) { + LEDRingSmall.LEDRingSmall_Set_GREEN(i, 0); + LEDRingSmall.LEDRingSmall_Set_BLUE(i, 0xff); + delay(30); + } + + for (i = 0; i < 24; i++) { + + LEDRingSmall.LEDRingSmall_Set_RGB(i, 0xfc6b03); + delay(30); + } + + for (i = 0; i < 24; i++) { + + LEDRingSmall.LEDRingSmall_Set_RGB(i, 0xfc03c6); + delay(30); + } +// delay(2000); + //LEDRingSmall.LEDRingSmall_ClearAll(); + + + + + for (tim = 0; tim < 2000; tim++) { + + + + if ((tim % 5) == 0) { + LEDRingSmall.LEDRingSmall_Set_RED(r, 0); + r = r + 1; + if (r >= 24) + r = 0; + LEDRingSmall.LEDRingSmall_Set_RED(r, 0xFF); + } + + if ((tim % 6) == 0) { + LEDRingSmall.LEDRingSmall_Set_GREEN(g, 0); + g = g + 1; + if (g >= 24) + g = 0; + LEDRingSmall.LEDRingSmall_Set_GREEN(g, 0xFF); + } + + if ((tim % 8) == 0) { + LEDRingSmall.LEDRingSmall_Set_BLUE(b, 0); + b = b + 1; + if (b >= 24) + b = 0; + LEDRingSmall.LEDRingSmall_Set_BLUE(b, 0xFF); + } + + + if ((tim % 7) == 0) { + LEDRingSmall.LEDRingSmall_Set_BLUE(br, 0); + LEDRingSmall.LEDRingSmall_Set_RED(br, 0); + br = br + 1; + if (br >= 24) + br = 0; + LEDRingSmall.LEDRingSmall_Set_BLUE(br, 0xFF); + LEDRingSmall.LEDRingSmall_Set_RED(br, 0xFF); + } + + + if ((tim % 10) == 0) { + LEDRingSmall.LEDRingSmall_Set_BLUE(bg, 0); + LEDRingSmall.LEDRingSmall_Set_GREEN(bg, 0); + bg = bg + 1; + if (bg >= 24) + bg = 0; + LEDRingSmall.LEDRingSmall_Set_BLUE(bg, 0xFF); + LEDRingSmall.LEDRingSmall_Set_GREEN(bg, 0xFF); + } + + if ((tim % 11) == 0) { + LEDRingSmall.LEDRingSmall_Set_RED(rg, 0); + LEDRingSmall.LEDRingSmall_Set_GREEN(rg, 0); + rg = rg + 1; + if (rg >= 24) + rg = 0; + LEDRingSmall.LEDRingSmall_Set_RED(rg, 0xFF); + LEDRingSmall.LEDRingSmall_Set_GREEN(rg, 0xFF); + } + + delay(10); + } + + + for (tim = 0; tim < 100; tim++) { + j = tim % 24; + + for (i = 0; i < 24; i++) { + LEDRingSmall.LEDRingSmall_Set_RGB(i, fade1_table[j]); + j++; + if (j >= 24) + j = 0; + } + delay(40); + } + + for (tim = 0; tim < 100; tim++) { + j = tim % 24; + for (i = 0; i < 24; i++) { + LEDRingSmall.LEDRingSmall_Set_RGB(i, fade2_table[j]); + j++; + if (j >= 24) + j = 0; + } + delay(40); + } + + for (i = 0xff; i > 0; i--) { + + LEDRingSmall.LEDRingSmall_GlobalCurrent(i); + delay(20); + } + LEDRingSmall.LEDRingSmall_ClearAll(); + LEDRingSmall.LEDRingSmall_GlobalCurrent(0xff); + + +} diff --git a/examples/RGB LED Ring Small/README.md b/examples/RGB LED Ring Small/README.md new file mode 100644 index 0000000..92fc649 --- /dev/null +++ b/examples/RGB LED Ring Small/README.md @@ -0,0 +1,90 @@ +# RGB LED Ring Arduino Library + +-------------------------------------------------------------------------------- + +## Introduction + +Here you can find the library description of the [RGB LED Ring](https://github.com/Fattoresaimon/RGB_LED_Ring) for the Arduino IDE. +The RGB LED Ring is based on the driver ISSI [IS31FL3737 ](http://www.issi.com/WW/pdf/31FL3737.pdf), for more functionality please check the datasheet of the driver. +At the moment the breathing effect are not implemented. + +The RGB LED Ring is available on [Tindie!]( https://www.tindie.com/products/20279/) + +## Initialization of the class + +The library makes available the class **LEDRing** +To initialize the library, you have to declare an instance of the class **LEDRing** for each LED Ring. +For example: + +``` C++ +LEDRing LEDRing(0x5A); +``` +Declaration of the RGB LED Ring with the jumper 0x5A soldered + + +## Configuration + +### void LEDRing_Reset(void) +Reset all the IS31FL3737 to the default state + +### void LEDRing_Configuration(uint8_t conf) +This method write the register ad the address 00h of the IS31FL3737. Please refer the datasheet for further information. + +### void LEDRing_GlobalCurrent(uint8_t conf) +This method write the register 01h and it set the LEDs current. +It's possible to set up to 256 step from 0 to 0xFF. +Higher value make the LEDs brighter. + +### void LEDRing_PULLUP(uint8_t pull) +### void LEDRing_PULLDOWN(uint8_t pull) +Configure the PULLUP or PULLDOWN resistor. +This resistor are used for avoid the "ghost" effect in a matrix LED architecture. +The possible value are the following: + +| PUR / PDR | Value | +| :--: | ---- | +| 000 | No pull-up resistor | +| 001 | 0.5kΩ | +| 010 | 1.0kΩ | +| 011 | 2.0kΩ | +| 100 | 4.0kΩ | +| 101 | 8.0kΩ | +| 110 | 16kΩ | +| 111 | 32kΩ | + +### void LEDRing_EnableAllOutput(void) +This method enable all the LEDs, by default the LEDs are disabled. + +### void LEDRing_DisableAllOutput(void) +This method disable all the LEDs. + +### void LEDRing_PWM_MODE(void) +This method set all the LEDs in PWM mode. + +### void LEDRing_ClearAll(void) +This method set the PWM value to 0 for each LED. + +### void LEDRing_Set_RGB(uint8_t led_n, uint32_t color) +Set the RGB color for a specific LED. +**n** is the LED number ( 0 to 47 ), while the **color** is the RGB color in 24bit format. + +#### Examples: + +```C++ + LEDRing.LEDRing_Set_RGB(10, 0xFF9933); +``` + +### void LEDRing_Set_RED(uint8_t led_n, uint8_t color) +### void LEDRing_Set_GREEN(uint8_t led_n, uint8_t color) +### void LEDRing_Set_BLUE(uint8_t led_n, uint8_t color) + +Set a specific color to a specific LED +**n** is the LED number ( 0 to 47 ), while the **color** is the color in 8bit format. + +#### Examples: + +```C++ + LEDRing.LEDRing_Set_RED(4, 128); + LEDRing.LEDRing_Set_GREEN(5, 200); + LEDRing.LEDRing_Set_BLUE(6, 80); +``` diff --git a/examples/RGB LED Ring/Demo/Demo.ino b/examples/RGB LED Ring/LEDRing_Demo/LEDRing_Demo.ino similarity index 84% rename from examples/RGB LED Ring/Demo/Demo.ino rename to examples/RGB LED Ring/LEDRing_Demo/LEDRing_Demo.ino index 0db5515..79db314 100644 --- a/examples/RGB LED Ring/Demo/Demo.ino +++ b/examples/RGB LED Ring/LEDRing_Demo/LEDRing_Demo.ino @@ -1,42 +1,39 @@ #include -#include +#include "LEDRing.h" /* + Connections with Arduino UNO: - VCC -> 5V - GND -> GND - VIO -> 5V + - -> GND + + -> 5V SDA -> A4 SCL -> A5 - INT -> //Not used now + INT -> A3 */ const uint32_t fade1_table[48] = {0x8011EE, 0x900AE5, 0xA004DA, 0xB001CD, 0xBF00BF, 0xCD01B0, 0xDA04A0, 0xE50A90, 0xEE1180, 0xF51A6F, 0xFB255F, 0xFE324F, 0xFF4040, 0xFE4F32, 0xFB5F25, 0xF56F1A, 0xEE8011, 0xE5900A, 0xDAA004, 0xCDB001, 0xBFBF00, 0xB0CD01, 0xA0DA04, 0x90E50A, 0x80EE11, 0x6FF51A, 0x5FFB25, 0x4FFE32, 0x40FF40, 0x32FE4F, 0x25FB5F, 0x1AF56F, 0x11EE80, 0x0AE590, 0x04DAA0, 0x01CDB0, 0x00BFBF, 0x01B0CD, 0x04A0DA, 0x0A90E5, 0x1180EE, 0x1A6FF5, 0x255FFB, 0x324FFE, 0x4040FF, 0x4F32FE, 0x5F25FB, 0x6F1AF5, }; const uint32_t fade2_table[48] = {0xFF0000, 0xFF0001, 0xFF0004, 0xFF000E, 0xFF0020, 0xFF003E, 0xFF006B, 0xFF00AB, 0xFF00FF, 0xAB00FF, 0x6B00FF, 0x3E00FF, 0x2000FF, 0x0E00FF, 0x0400FF, 0x0100FF, 0x0000FF, 0x0001FF, 0x0004FF, 0x000EFF, 0x0020FF, 0x003EFF, 0x006BFF, 0x00ABFF, 0x00FFFF, 0x00FFAB, 0x00FF6B, 0x00FF3E, 0x00FF20, 0x00FF0E, 0x00FF04, 0x00FF01, 0x00FF00, 0x01FF00, 0x04FF00, 0x0EFF00, 0x20FF00, 0x3EFF00, 0x6BFF00, 0xABFF00, 0xFFFF00, 0xFFAB00, 0xFF6B00, 0xFF3E00, 0xFF2000, 0xFF0E00, 0xFF0400, 0xFF0100, }; -uint8_t j = 0; -uint8_t i = 0; -uint16_t tim = 0; -uint8_t r = 5, g = 8, b = 20, rg = 40, br = 35, bg = 17; - - -LEDRing LEDRing(0x5A); // change the adress according to your board. +static uint8_t j = 0; +static uint8_t i = 0; +static uint16_t tim = 0; +static uint8_t r = 5, g = 8, b = 20, rg = 40, br = 35, bg = 17; +LEDRing LEDRing(ISSI3745_SJ1 | ISSI3745_SJ5); void setup(void) { Wire.begin(); - + Wire.setClock(400000); LEDRing.LEDRing_Reset(); delay(20); - LEDRing.LEDRing_EnableAllOutput(); LEDRing.LEDRing_Configuration(0x01); //Normal operation - LEDRing.LEDRing_GlobalCurrent(0xff); // maximum current output - LEDRing.LEDRing_PULLUP(0b111); // 32k pull-up resistor for avoid ghost effect - LEDRing.LEDRing_PULLDOWN(0b111); // 32k pull-down resistor for avoid ghost effect - LEDRing.LEDRing_PWM_MODE(); //Exit to the configuration mode and enter in PWM mode + LEDRing.LEDRing_SpreadSpectrum(0b0010110); + LEDRing.LEDRing_GlobalCurrent(0xFf); // maximum current output + LEDRing.LEDRing_SetScaling(0xFF); + LEDRing.LEDRing_PWM_MODE(); } void loop() { @@ -69,6 +66,13 @@ void loop() { LEDRing.LEDRing_Set_RGB(i, 0xFF9933); delay(15); } + + for (i = 0; i < 48; i++) { + + LEDRing.LEDRing_Set_RGB(i, 0xFFFFFF); + delay(15); + } + LEDRing.LEDRing_ClearAll(); @@ -167,6 +171,6 @@ void loop() { LEDRing.LEDRing_ClearAll(); LEDRing.LEDRing_GlobalCurrent(0xff); delay(1000); - LEDRing.LEDRing_PWM_MODE(); //Exit to the configuration mode and enter in PWM mode + LEDRing.LEDRing_PWM_MODE(); } diff --git a/src/LEDRing.cpp b/src/LEDRing.cpp index 7b5d0fc..170f78a 100644 --- a/src/LEDRing.cpp +++ b/src/LEDRing.cpp @@ -12,55 +12,63 @@ // Simone Caron // +// datasheet of the controller: https://www.lumISSI3745l.com/assets/pdf/core/IS31FL3745_DS.pdf + #include "LEDRing.h" #include LEDRing::LEDRing(uint8_t add) { _add = add; + } void LEDRing::LEDRing_PWM_MODE(void) { - selectBank(ISSI_PAGE2); + selectBank(ISSI3745_PAGE0); } -void LEDRing::LEDRing_Reset(void) { - selectBank(ISSI_PAGE4); - Wire.beginTransmission(_add); - Wire.write((byte)RESET_REG); - Wire.endTransmission(); - Wire.requestFrom(_add, (uint8_t) 1); - Wire.endTransmission(); +void LEDRing::LEDRing_Configuration(uint8_t conf) { + selectBank(ISSI3745_PAGE2); + writeRegister8(ISSI3745_CONFIGURATION, conf); +} +void LEDRing::LEDRing_SetScaling(uint8_t led_n, uint8_t scal) { + selectBank(ISSI3745_PAGE1); + writeRegister8(led_n, scal); } -void LEDRing::LEDRing_Configuration(uint8_t conf) { - selectBank(ISSI_PAGE4); - writeRegister8(ISSI_CONFIGURATION, conf); +void LEDRing::LEDRing_SetScaling(uint8_t scal) { + selectBank(ISSI3745_PAGE1); + + for (uint8_t i = 1; i < 145; i++) { + writeRegister8(i, scal); + } } -void LEDRing::LEDRing_PULLUP(uint8_t pull) { - selectBank(ISSI_PAGE4); - writeRegister8(ISSI_PULLUP, pull); +void LEDRing::LEDRing_GlobalCurrent(uint8_t curr) { + selectBank(ISSI3745_PAGE2); + writeRegister8(ISSI3745_GLOBALCURRENT, curr); } -void LEDRing::LEDRing_PULLDOWN(uint8_t pull) { - selectBank(ISSI_PAGE4); - writeRegister8(ISSI_PULLDOWN, pull); +void LEDRing::LEDRing_PULLUP_DOWN(uint8_t pull) { + selectBank(ISSI3745_PAGE2); + writeRegister8(ISSI3745_PULLUPDOWM, pull); } +uint8_t LEDRing::LEDRing_Temperature(void) { + selectBank(ISSI3745_PAGE2); + return (readRegister8(ISSI3745_TEMPERATURE)); +} -void LEDRing::LEDRing_GlobalCurrent(uint8_t curr) { - selectBank(ISSI_PAGE4); - writeRegister8(ISSI_GLOBALCURRENT, curr); +void LEDRing::LEDRing_SpreadSpectrum(uint8_t spread) { + selectBank(ISSI3745_PAGE2); + writeRegister8(ISSI3745_SPREADSPECTRUM, spread); } +void LEDRing::LEDRing_Reset(void) { + selectBank(ISSI3745_PAGE2); + writeRegister8(ISSI3745_RESET_REG, 0xAE); -void LEDRing::LEDRing_EnableAllOutput(void) { - selectBank(ISSI_PAGE1); - for (uint8_t i = 0; i < 0x24; i++) { - writeRegister8(i, 0xff); - } } void LEDRing::LEDRing_Set_RGB(uint8_t led_n, uint32_t color) { @@ -71,7 +79,6 @@ void LEDRing::LEDRing_Set_RGB(uint8_t led_n, uint32_t color) { } - void LEDRing::LEDRing_Set_RED(uint8_t led_n, uint8_t color) { writeRegister8(issi_led_map[0][led_n], color); @@ -91,19 +98,19 @@ void LEDRing::LEDRing_Set_BLUE(uint8_t led_n, uint8_t color) { void LEDRing::LEDRing_ClearAll(void) { - uint8_t buff[6] = {0}; - uint8_t i = 0x00; + uint8_t i; + LEDRing_PWM_MODE(); - while (i <= 0xB0) { - writeBuff(i, buff, 6); - writeBuff((i + 0x08), buff, 6); - i = i + 0x10; + + for (i = 1; i < 145; i++) { + writeRegister8(i,0); } + } void LEDRing::selectBank(uint8_t b) { - writeRegister8(ISSI_COMMANDREGISTER_LOCK, ISSI_ULOCK_CODE); - writeRegister8(ISSI_COMMANDREGISTER, b); + writeRegister8(ISSI3745_COMMANDREGISTER_LOCK, ISSI3745_ULOCK_CODE); + writeRegister8(ISSI3745_COMMANDREGISTER, b); } void LEDRing::writeRegister8(uint8_t reg, uint8_t data) { @@ -120,3 +127,16 @@ void LEDRing::writeBuff(uint8_t reg, uint8_t *data, uint8_t dim) { Wire.endTransmission(); } + +uint8_t LEDRing::readRegister8(uint8_t reg) { + byte rdata = 0xFF; + + Wire.beginTransmission(_add); + Wire.write(reg); + Wire.endTransmission(); + Wire.requestFrom(_add, (uint8_t) 1); + if (Wire.available()) { + rdata = Wire.read(); + } + return rdata; +} diff --git a/src/LEDRing.h b/src/LEDRing.h index 7d3d3d5..6193e45 100644 --- a/src/LEDRing.h +++ b/src/LEDRing.h @@ -21,53 +21,67 @@ #include #endif -#define ISSI_PAGE1 0x00 -#define ISSI_PAGE2 0x01 -#define ISSI_PAGE3 0x02 -#define ISSI_PAGE4 0x03 - -#define ISSI_COMMANDREGISTER 0xFD -#define ISSI_COMMANDREGISTER_LOCK 0xFE -#define ISSI_INT_MASK 0xF0 -#define ISSI_INT_STATUS 0xF1 -#define ISSI_CONFIGURATION 0x00 -#define ISSI_GLOBALCURRENT 0x01 - -#define ISSI_PULLUP 0x0F -#define ISSI_PULLDOWN 0x10 -#define ISSI_ULOCK_CODE 0xC5 -#define RESET_REG 0x11 +#define ISSI3745_PAGE0 0x00 +#define ISSI3745_PAGE1 0x01 +#define ISSI3745_PAGE2 0x02 + +#define ISSI3745_COMMANDREGISTER 0xFD +#define ISSI3745_COMMANDREGISTER_LOCK 0xFE +#define ISSI3745_ULOCK_CODE 0xC5 + +#define ISSI3745_CONFIGURATION 0x00 +#define ISSI3745_GLOBALCURRENT 0x01 +#define ISSI3745_PULLUPDOWM 0x02 +#define ISSI3745_OPENSHORT 0x03 +#define ISSI3745_TEMPERATURE 0x24 +#define ISSI3745_SPREADSPECTRUM 0x25 +#define ISSI3745_RESET_REG 0x2F + + +#define ISSI3745_SJ1 0b0100000 +#define ISSI3745_SJ2 0b0100001 +#define ISSI3745_SJ3 0b0100010 +#define ISSI3745_SJ4 0b0100011 +#define ISSI3745_SJ5 0b0100000 +#define ISSI3745_SJ6 0b0100100 +#define ISSI3745_SJ7 0b0101000 +#define ISSI3745_SJ8 0b0101100 + + + + class LEDRing { public: LEDRing(uint8_t add); void LEDRing_PWM_MODE(void); - void LEDRing_ClearAll(void); + void LEDRing_Configuration(uint8_t conf); + void LEDRing_SetScaling(uint8_t led_n, uint8_t scal); + void LEDRing_SetScaling(uint8_t scal); + void LEDRing_GlobalCurrent(uint8_t curr); + void LEDRing_PULLUP_DOWN(uint8_t pull); + uint8_t LEDRing_Temperature(void); + void LEDRing_SpreadSpectrum(uint8_t spread); + void LEDRing_Reset(void); + void LEDRing_Set_RGB(uint8_t led_n, uint32_t color); void LEDRing_Set_RED(uint8_t led_n, uint8_t color); void LEDRing_Set_GREEN(uint8_t led_n, uint8_t color); void LEDRing_Set_BLUE(uint8_t led_n, uint8_t color); - - void LEDRing_Reset(void); - void LEDRing_EnableAllOutput(void); - void LEDRing_GlobalCurrent(uint8_t curr); - void LEDRing_Configuration(uint8_t conf); - void LEDRing_PULLUP(uint8_t pull); - void LEDRing_PULLDOWN(uint8_t pull); - - + void LEDRing_ClearAll(void); private: const uint8_t issi_led_map[3][48] = { - {0xAD, 0xAC, 0xAB, 0xAA, 0xA9, 0xA8, 0xA5, 0xA4, 0xA3, 0xA2, 0xA1, 0xA0, 0x7D, 0x7C, 0x7B, 0x7A, 0x79, 0x78, 0x75, 0x74, 0x73, 0x72, 0x71, 0x70, 0x4D, 0x4C, 0x4B, 0x4A, 0x49, 0x48, 0x45, 0x44, 0x43, 0x42, 0x41, 0x40, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10}, // Red - {0x9D, 0x9C, 0x9B, 0x9A, 0x99, 0x98, 0x95, 0x94, 0x93, 0x92, 0x91, 0x90, 0x6D, 0x6C, 0x6B, 0x6A, 0x69, 0x68, 0x65, 0x64, 0x63, 0x62, 0x61, 0x60, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00}, // Green - {0xBD, 0xBC, 0xBB, 0xBA, 0xB9, 0xB8, 0xB5, 0xB4, 0xB3, 0xB2, 0xB1, 0xB0, 0x8D, 0x8C, 0x8B, 0x8A, 0x89, 0x88, 0x85, 0x84, 0x83, 0x82, 0x81, 0x80, 0x5D, 0x5C, 0x5B, 0x5A, 0x59, 0x58, 0x55, 0x54, 0x53, 0x52, 0x51, 0x50, 0x2D, 0x2C, 0x2B, 0x2A, 0x29, 0x28, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20}, // Blue + {0x12, 0x24, 0x36, 0x48, 0x5A, 0x6C, 0x7E, 0x90, 0xF, 0x21, 0x33, 0x45, 0x57, 0x69, 0x7B, 0x8D, 0xC, 0x1E, 0x30, 0x42, 0x54, 0x66, 0x78, 0x8A, 0x9, 0x1B, 0x2D, 0x3F, 0x51, 0x63, 0x75, 0x87, 0x6, 0x18, 0x2A, 0x3C, 0x4E, 0x60, 0x72, 0x84, 0x3, 0x15, 0x27, 0x39, 0x4B, 0x5D, 0x6F, 0x81}, // Red + {0x11, 0x23, 0x35, 0x47, 0x59, 0x6B, 0x7D, 0x8F, 0xE, 0x20, 0x32, 0x44, 0x56, 0x68, 0x7A, 0x8C, 0xB, 0x1D, 0x2F, 0x41, 0x53, 0x65, 0x77, 0x89, 0x8, 0x1A, 0x2C, 0x3E, 0x50, 0x62, 0x74, 0x86, 0x5, 0x17, 0x29, 0x3B, 0x4D, 0x5F, 0x71, 0x83, 0x2, 0x14, 0x26, 0x38, 0x4A, 0x5C, 0x6E, 0x80}, //Green + {0x10, 0x22, 0x34, 0x46, 0x58, 0x6A, 0x7C, 0x8E, 0xD, 0x1F, 0x31, 0x43, 0x55, 0x67, 0x79, 0x8B, 0xA, 0x1C, 0x2E, 0x40, 0x52, 0x64, 0x76, 0x88, 0x7, 0x19, 0x2B, 0x3D, 0x4F, 0x61, 0x73, 0x85, 0x4, 0x16, 0x28, 0x3A, 0x4C, 0x5E, 0x70, 0x82, 0x1, 0x13, 0x25, 0x37, 0x49, 0x5B, 0x6D, 0x7F} //Blue }; - + uint8_t _add; void selectBank(uint8_t b); void writeRegister8(uint8_t reg, uint8_t data); void writeBuff(uint8_t reg, uint8_t *data, uint8_t dim); + uint8_t readRegister8(uint8_t reg); }; #endif diff --git a/src/LEDRingSmall.cpp b/src/LEDRingSmall.cpp new file mode 100644 index 0000000..4105cc0 --- /dev/null +++ b/src/LEDRingSmall.cpp @@ -0,0 +1,147 @@ +// +// FILE: LEDRingSmall.c +// VERSION: 1.0.. +// PURPOSE: Library for LEDRingSmall from DUPPA +// LICENSE: GPL v3 (http://www.gnu.org/licenses/gpl.html) +// +// DATASHEET: +// +// URL: +// +// AUTHOR: +// Simone Caron +// + +// datasheet of the controller: https://www.lumissil.com/assets/pdf/core/IS31FL3746A_DS.pdf + +#include "LEDRingSmall.h" +#include + +LEDRingSmall::LEDRingSmall(uint8_t add) { + _add = add; +} + +void LEDRingSmall::LEDRingSmall_PWM_MODE(void) { + selectBank(ISSI3746_PAGE0); +} + +void LEDRingSmall::LEDRingSmall_Configuration(uint8_t conf) { + selectBank(ISSI3746_PAGE1); + writeRegister8(ISSI3746_CONFIGURATION, conf); +} + +void LEDRingSmall::LEDRingSmall_SetScaling(uint8_t led_n, uint8_t scal) { + selectBank(ISSI3746_PAGE1); + writeRegister8(led_n, scal); +} + +void LEDRingSmall::LEDRingSmall_SetScaling(uint8_t scal) { + selectBank(ISSI3746_PAGE1); + + for (uint8_t i = 1; i < 73; i++) { + writeRegister8(i, scal); + } +} + +void LEDRingSmall::LEDRingSmall_GlobalCurrent(uint8_t curr) { + selectBank(ISSI3746_PAGE1); + writeRegister8(ISSI3746_GLOBALCURRENT, curr); +} + +void LEDRingSmall::LEDRingSmall_PULLUP_DOWN(uint8_t pull) { + selectBank(ISSI3746_PAGE1); + writeRegister8(ISSI3746_PULLUPDOWM, pull); +} + + +uint8_t LEDRingSmall::LEDRingSmall_Temperature(void) { + selectBank(ISSI3746_PAGE1); + return(readRegister8(ISSI3746_TEMPERATURE)); +} + +void LEDRingSmall::LEDRingSmall_SpreadSpectrum(uint8_t spread) { + selectBank(ISSI3746_PAGE1); + writeRegister8(ISSI3746_SPREADSPECTRUM, spread); +} + +void LEDRingSmall::LEDRingSmall_Reset(void) { + selectBank(ISSI3746_PAGE1); + writeRegister8(ISSI3746_RESET_REG, 0xAE); +} + +void LEDRingSmall::LEDRingSmall_PWMFrequencyEnable(uint8_t PWMenable) { + selectBank(ISSI3746_PAGE1); + writeRegister8(ISSI3746_PWM_FREQUENCY_ENABLE, PWMenable); +} + +void LEDRingSmall::LEDRingSmall_PWMFrequencySetting(uint8_t pwmfreq) { + selectBank(ISSI3746_PAGE1); + writeRegister8(ISSI3746_PWM_FREQUENCY_SET, pwmfreq); +} + + +void LEDRingSmall::LEDRingSmall_Set_RGB(uint8_t led_n, uint32_t color) { + + writeRegister8(issi_led_map[0][led_n], ((color >> 16) & 0xFF)); + writeRegister8(issi_led_map[1][led_n], ((color >> 8) & 0xFF)); + writeRegister8(issi_led_map[2][led_n], (color & 0xFF)); +} + +void LEDRingSmall::LEDRingSmall_Set_RED(uint8_t led_n, uint8_t color) { + + writeRegister8(issi_led_map[0][led_n], color); +} + +void LEDRingSmall::LEDRingSmall_Set_GREEN(uint8_t led_n, uint8_t color) { + + writeRegister8(issi_led_map[1][led_n], color); + +} + +void LEDRingSmall::LEDRingSmall_Set_BLUE(uint8_t led_n, uint8_t color) { + + writeRegister8(issi_led_map[2][led_n], color); +} + +void LEDRingSmall::LEDRingSmall_ClearAll(void) { + uint8_t i; + LEDRingSmall_PWM_MODE(); + + for (i = 1; i < 73; i++) { + writeRegister8(i,0); + } + +} + + +void LEDRingSmall::selectBank(uint8_t b) { + writeRegister8(ISSI3746_COMMANDREGISTER_LOCK, ISSI3746_ULOCK_CODE); + writeRegister8(ISSI3746_COMMANDREGISTER, b); +} + +void LEDRingSmall::writeRegister8(uint8_t reg, uint8_t data) { + Wire.beginTransmission(_add); + Wire.write(reg); + Wire.write(data); + Wire.endTransmission(); +} + +void LEDRingSmall::writeBuff(uint8_t reg, uint8_t *data, uint8_t dim) { + Wire.beginTransmission(_add); + Wire.write(reg); + Wire.write(data, dim); + Wire.endTransmission(); +} + +uint8_t LEDRingSmall::readRegister8(uint8_t reg) { + byte rdata = 0xFF; + + Wire.beginTransmission(_add); + Wire.write(reg); + Wire.endTransmission(); + Wire.requestFrom(_add, (uint8_t) 1); + if (Wire.available()) { + rdata = Wire.read(); + } + return rdata; +} diff --git a/src/LEDRingSmall.h b/src/LEDRingSmall.h new file mode 100644 index 0000000..794ad0a --- /dev/null +++ b/src/LEDRingSmall.h @@ -0,0 +1,89 @@ +// +// FILE: LEDRingSmall.h +// VERSION: 1.0.. +// PURPOSE: Library for LEDRingSmall from DUPPA +// LICENSE: GPL v3 (http://www.gnu.org/licenses/gpl.html) +// +// DATASHEET: +// +// URL: +// +// AUTHOR: +// Simone Caron +// + +#ifndef LEDRingSmall_H +#define LEDRingSmall_H + +#if (ARDUINO >= 100) +#include +#else +#include +#endif + +#define ISSI3746_PAGE0 0x00 +#define ISSI3746_PAGE1 0x01 + + +#define ISSI3746_COMMANDREGISTER 0xFD +#define ISSI3746_COMMANDREGISTER_LOCK 0xFE +#define ISSI3746_ID_REGISTER 0xFC +#define ISSI3746_ULOCK_CODE 0xC5 + +#define ISSI3746_CONFIGURATION 0x50 +#define ISSI3746_GLOBALCURRENT 0x51 +#define ISSI3746_PULLUPDOWM 0x52 +#define ISSI3746_OPENSHORT 0x53 +#define ISSI3746_TEMPERATURE 0x5F +#define ISSI3746_SPREADSPECTRUM 0x60 +#define ISSI3746_RESET_REG 0x8F +#define ISSI3746_PWM_FREQUENCY_ENABLE 0xE0 +#define ISSI3746_PWM_FREQUENCY_SET 0xE2 + + +#define ISSI3746_SJ1 0b1100000 +#define ISSI3746_SJ2 0b1100001 +#define ISSI3746_SJ3 0b1100010 +#define ISSI3746_SJ4 0b1100011 +#define ISSI3746_SJ5 0b1100000 +#define ISSI3746_SJ6 0b1100100 +#define ISSI3746_SJ7 0b1101000 +#define ISSI3746_SJ8 0b1101100 + + +class LEDRingSmall { + public: + + LEDRingSmall(uint8_t add); + void LEDRingSmall_PWM_MODE(void); + void LEDRingSmall_Configuration(uint8_t conf); + void LEDRingSmall_SetScaling(uint8_t led_n, uint8_t scal); + void LEDRingSmall_SetScaling(uint8_t scal); + void LEDRingSmall_GlobalCurrent(uint8_t curr); + void LEDRingSmall_PULLUP_DOWN(uint8_t pull); + uint8_t LEDRingSmall_Temperature(void); + void LEDRingSmall_SpreadSpectrum(uint8_t spread); + void LEDRingSmall_Reset(void); + void LEDRingSmall_PWMFrequencyEnable(uint8_t PWMenable); + void LEDRingSmall_PWMFrequencySetting(uint8_t pwmfreq); + + void LEDRingSmall_Set_RGB(uint8_t led_n, uint32_t color); + void LEDRingSmall_Set_RED(uint8_t led_n, uint8_t color); + void LEDRingSmall_Set_GREEN(uint8_t led_n, uint8_t color); + void LEDRingSmall_Set_BLUE(uint8_t led_n, uint8_t color); + void LEDRingSmall_ClearAll(void); + + private: + const uint8_t issi_led_map[3][24] = { + {0x48, 0x36, 0x24, 0x12, 0x45, 0x33, 0x21, 0x0F, 0x42, 0x30, 0x1E, 0x0C, 0x3F, 0x2D, 0x1B, 0x09, 0x3C, 0x2A, 0x18, 0x06, 0x39, 0x27, 0x15, 0x03}, // Red + {0x47, 0x35, 0x23, 0x11, 0x44, 0x32, 0x20, 0x0E, 0x41, 0x2F, 0x1D, 0x0B, 0x3E, 0x2C, 0x1A, 0x08, 0x3B, 0x29, 0x17, 0x05, 0x38, 0x26, 0x14, 0x02}, //Green + {0x46, 0x34, 0x22, 0x10, 0x43, 0x31, 0x1F, 0x0D, 0x40, 0x2E, 0x1C, 0x0A, 0x3D, 0x2B, 0x19, 0x07, 0x3A, 0x28, 0x16, 0x04, 0x37, 0x25, 0x13, 0x01}, //Blue + }; + + uint8_t _add; + void selectBank(uint8_t b); + void writeRegister8(uint8_t reg, uint8_t data); + void writeBuff(uint8_t reg, uint8_t *data, uint8_t dim); + uint8_t readRegister8(uint8_t reg); +}; +#endif