Addressable RGB LED's

MSqDT:
@PaulRB

Trialled your code.

I got the LED's lighting up one after the other and repeating the effect after a short delay. The colour is close to white with no change. Linking to other replies I am interested and still licking this breadboard out of curiosity, but I have moved on with the main work.

If you want to post me one or two of the leds, i can see if i can get them working.

I have breadboarded these and now produced a PCB to run them successfully. I now hope to use this to learn more about the coding of the RGB led's.

Be sure to use the correct address.

I have got these working if anyone is still interested.

Here follow two programs, one for simple control, and the other setting up an array of colours:

/*Code for driving OST4ML5B32A addressable rgb leds
 * Developed by Oliver Rokison at Hampton School
 * 
 * The circuit for the first LED in the string is as follows:
 * Pin 1 (DIN) to pin 3 on Arduino
 * Pin 2 (VDD) to 5V on Arduino
 * Pin 3 (GND) to GND on Arduino
 * Pin 4 (DOUT) to DIN of next LED
 * 
 * You MUST also connect a 1K resistor fron Pin 1 to 5V, and a 1K resistor from Pin 1 to 0V (on the first LED only)
 * This gives the three voltage levels required by the LED
 * 
 * Connect other LEDs in the same way, but with Pin 1 (DIN) connected to Pin 4 (DOUT) of the previous LED
 */

#define LED_PIN 3 // the data pin from the Arduino to your string of LEDs
#define DELAY 50 // the pulse width in microseconds (plus the 2 microseconds or so that the digitalWrite command takes)

void setup() {
  pinMode(LED_PIN, INPUT);

}

void loop() {
  // the sendColour command takes 3 bytes (R,G & B values from 0-255) and displays that colour on the LED
  sendColour(0, 255, 0); //Note, this will control the last LED in your string
  //place other sendColour commands in here depending on how many LEDs in your string
  sendColour(255,0,0); //This will control the first LED
  delay(10); // datasheet requires at least 3ms between refreshes, but we have used 10 for safety
}

void sendColour(byte r, byte g, byte b) {
  sendByte(b); // we send the blue first
  sendByte(g); // then the green
  sendByte(r); // then the blue
}

void sendByte(byte b) {
  // each byte is sent LSB first and is 8 bits long
  for (int n = 7; n >= 0; n--) {
    // if we have a high bit, set up the digitalWrite first, then make the pin an output
    // this will engage the 10K internal pullup resistor, but in compariosn to our 1K potential divider, this shouldn't affect the logic level
    if (bitRead(b, n)) { 
      digitalWrite(LED_PIN, HIGH);
      pinMode(LED_PIN, OUTPUT);
      delayMicroseconds(DELAY);
      pinMode(LED_PIN, INPUT);
      delayMicroseconds(DELAY);
    }
    // otherwise, if we have a low bit, make the pin an output first and then check it is LOW
    else {
      pinMode(LED_PIN, OUTPUT);
      digitalWrite(LED_PIN, LOW);
      delayMicroseconds(DELAY);
      pinMode(LED_PIN, INPUT);
      delayMicroseconds(DELAY);
    }
  }
}

And now with an array:

/* Code for driving OST4ML5B32A addressable rgb leds
 * Developed by Oliver Rokison of Hampton School
 *  
 * The circuit for the first LED in the string is as follows:
 * Pin 1 (DIN) to pin 3 on Arduino
 * Pin 2 (VDD) to 5V on Arduino
 * Pin 3 (GND) to GND on Arduino
 * Pin 4 (DOUT) to DIN of next LED
 * 
 * You MUST also connect a 1K resistor fron Pin 1 to 5V, and a 1K resistor from Pin 1 to 0V (on the first LED only)
 * This gives the three voltage levels required by the LED
 * 
 * Connect other LEDs in the same way, but with Pin 1 (DIN) connected to Pin 4 (DOUT) of the previous LED
 */

#define LED_PIN 3 // the data pin from the Arduino to your string of LEDs
#define DELAY 50 // the pulse width in microseconds (plus the 2 microseconds or so that the digitalWrite command takes)

// this is where you define the RGB colours you want each LED to display, startng with the one nearest the Arduino
byte Colours[][3]={
  {0,255,0},
  {255,0,0},
};

void setup() {
  pinMode(LED_PIN, INPUT);

}

void loop() {
  // the colours are set in reverse order
  for(int i=((sizeof(Colours)/sizeof(byte))/3)-1; i>=0;i--){
    // the sendColour command takes 3 bytes (R,G & B values from 0-255) and displays that colour on the LED
    sendColour(Colours[i][0], Colours[i][1],Colours[i][2]); //Note, this will control the last LED in your string
  }
  delay(10); // datasheet requires at least 3ms between refreshes, but we have used 10 for safety, and we only do this at the end
}

void sendColour(byte r, byte g, byte b) {
  sendByte(b); // we send the blue first
  sendByte(g); // then the green
  sendByte(r); // then the blue
}

void sendByte(byte b) {
  // each byte is sent LSB first and is 8 bits long
  for (int n = 7; n >= 0; n--) {
    // if we have a high bit, set up the digitalWrite first, then make the pin an output
    // this will engage the 10K internal pullup resistor, but in compariosn to our 1K potential divider, this shouldn't affect the logic level
    if (bitRead(b, n)) { 
      digitalWrite(LED_PIN, HIGH);
      pinMode(LED_PIN, OUTPUT);
      delayMicroseconds(DELAY);
      pinMode(LED_PIN, INPUT);
      delayMicroseconds(DELAY);
    }
    // otherwise, if we have a low bit, make the pin an output first and then check it is LOW
    else {
      pinMode(LED_PIN, OUTPUT);
      digitalWrite(LED_PIN, LOW);
      delayMicroseconds(DELAY);
      pinMode(LED_PIN, INPUT);
      delayMicroseconds(DELAY);
    }
  }
}

Well done for getting it working! I would love to know why your code works and my suggested code did not. Do you have any idea about that? My code seems very similar, on the face of it, but shorter.