Grove - Chainable RGB LED

From Wiki 来自痴汉的爱
(Redirected from Twig - Chainable RGB LED)
Jump to: navigation, search





Chainable RGB LED is based on P9813 chip which is a full-color light source LED driver chip, and can provide constant current drive and modulated output of 256 gray. Transmission by wire (DATA and CLK), built-in recycling, can enhance the transmission distance.

Model: COM53140P


  • Operating Voltage: 5V
  • Operating Current: 20mA
  • Communication Protocol: Serial


When you get Grove - Chainble RGB LED, you may think how I can light up it. Now we will show you this demo: all colors of RGB cycles in an uniform way.
The hardware installation like this:

To complete this demo, you can use one or more Grove - Chainable RGB LED. Note that the IN interface of one Grove - Chainable RGB LED should be connect to D7/D8 of Grove - Base Shield and its OUT interface connect to IN interface of another Grove - Chainable RGB LED, chainable more LED in this way. Jasa seo, Jasa seo jakarta

 * Example of using the ChainableRGB library for controlling a Grove RGB.
 * This code cycles through all the colors in an uniform way. This is accomplished using a HSB color space. 
#include <ChainableLED.h>

#define NUM_LEDS  5

ChainableLED leds(7, 8, NUM_LEDS);

void setup()

float hue = 0.0;
boolean up = true;

void loop()
  for (byte i=0; i<NUM_LEDS; i++)
    leds.setColorHSB(i, hue, 1.0, 0.5);
  if (up)
    hue+= 0.025;
    hue-= 0.025;
  if (hue>=1.0 && up)
    up = false;
  else if (hue<=0.0 && !up)
    up = true;

You can observe this scene: colors of two LED will gradient consistently.

Extend application:
Based on Chainable LED Library, we have designed this demo: RGB color varies with the temperature measured by Grove - temperature. The RGB color vary from green to red when the temperature is from 25 to 32. The test code is shown below. Do it if you are interested in it.

// demo of temperature -> rgbLED
// temperature form 25 - 32, rgbLed from green -> red
// Grove-temperature plu to A0
// LED plug to D7,D8

#include <Streaming.h>
#include <ChainableLED.h>

#define TEMPUP 32
#define TEMPDOWN 25

ChainableLED leds(7, 8, 1); // connect to pin7 and pin8 , one led

int getAnalog() // get value from A0
    int sum = 0;
    for(int i=0; i<32; i++)
        sum += analogRead(A0);
    return sum>>5;

float getTemp() // get temperature
    float temperature = 0.0;
    float resistance = 0.0;
    int B = 3975; //B value of the thermistor
    int a = getAnalog();
    resistance = (float)(1023-a)*10000/a; //get the resistance of the sensor;
    temperature = 1/(log(resistance/10000)/B+1/298.15)-273.15; //convert to temperature via datasheet ;
    return temperature;

void ledLight(int dta) // light led

    dta = dta/4; // 0 - 255
    int colorR = dta;
    int colorG = 255-dta;
    int colorB = 0;

    leds.setColorRGB(0, colorR, colorG, colorB);

void setup()
    cout << "hello world !" << endl;

void loop()
    float temp = getTemp();
    int nTemp = temp*100;
    nTemp = nTemp > TEMPUP*100 ? TEMPUP*100 : (nTemp < TEMPDOWN*100 ? TEMPDOWN*100 : nTemp);
    nTemp = map(nTemp, TEMPDOWN*100, TEMPUP*100, 0, 1023);


Personal tools

Start here|开始探索