LED Problems

so i found this code online but only half my LEDs turn on. I have 60 LEDs but the code was made for 30.

/*---------------------------------------------------------*\
|                                                           |
|   WS2812B (NeoPixel) Serial Controlled LED Strip Driver   |
|     for use with Keyboard Visualizer VCUI                 |
|                                                           |
|   Adam Honse (calcprogrammer1) 1/22/2016                  |
|                                                           |
\*---------------------------------------------------------*/
#include 
#ifdef __AVR__
  #include 
#endif

#define PIN 3

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  // NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
 //  NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(59, PIN, NEO_RGB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.
unsigned char serial_buffer[92];

void setup()
{
  Serial.begin(115200);
  strip.begin();
  strip.show();
}

void loop()
{
if( Serial.available() )
  {
  for( int i = 0; i < 91; i++ )
  {
    serial_buffer[i] = serial_buffer[i+1];
  }
  serial_buffer[91] = Serial.read();

  unsigned char sum = 0;
  for( int i = 0; i < 91; i++ )
  {
    sum += serial_buffer[i];
  }
  //Test if valid write packet
  if(serial_buffer[0] == 0xAA && serial_buffer[91] == sum)
  {
    for( int i = 0; i < 30; i++ )
    {
      int idx = 1 + ( 3 * i );
      strip.setPixelColor(i, strip.Color(serial_buffer[idx], serial_buffer[idx+1], serial_buffer[idx+2]));
    }
    noInterrupts();
    strip.show();
    interrupts();
  }
  }
}

My LEDs work fine because when i put my own code all 60 turn on.

Everything you say makes perfect sense. Is there a question?

aarg: Everything you say makes perfect sense. Is there a question?

only 30 leds turn on so how do i make it turn on 60 with the code i provided?

    for( int i = 0; i < 30; i++ )

Did you read the code, or did you just throw your hands up in despair before even starting?

aarg:     for( int i = 0; i < 30; i++ )

Did you read the code, or did you just throw your hands up in despair before even starting?

LOL i havent laughed so hard in years. I forgot to mention i am a newbie at this since i started today. So my question still stands.

You are parsing a packet of 92 bytes, 0xAA (30 * RGB) checksum. How should this data be distributed to your 60 LED array?

Current solution: put the data in the first 30 LEDs only (the for above).

Why do you state to have 59 LEDs?

// Parameter 1 = number of pixels in strip
Adafruit_NeoPixel strip = Adafruit_NeoPixel(59, PIN, NEO_RGB + NEO_KHZ800);

Whandall: You are parsing a packet of 92 bytes, 0xAA (30 * RGB) checksum. How should this data be distributed to your 60 LED array?

Current solution: put the data in the first 30 LEDs only (the for above).

Why do you state to have 59 LEDs?

// Parameter 1 = number of pixels in strip
Adafruit_NeoPixel strip = Adafruit_NeoPixel(59, PIN, NEO_RGB + NEO_KHZ800);

Well the 59 must have been an accident currently i have it at 60 and about the data being distributed to my 60 led array i have no clue about. i just started today so i dont know much about programming... :(

If you don't want to learn programming, you have to run the cut and paste code as it is. Sometimes that even works.

waffle212121212: about the data being distributed to my 60 led array i have no clue about.

If you don't have a clue which LED should show which color, I run out of suggestions.

Unless you want to replicate projects exactly, you are going to have to start with some easier projects. You have to learn the basics before you can tackle complicated code by yourself.

aarg: Unless you want to replicate projects exactly, you are going to have to start with some easier projects. You have to learn the basics before you can tackle complicated code by yourself.

thanks for nothing. i figured it out by using this.

strip.setPixelColor(i*2, strip.Color(serial_buffer[idx], serial_buffer[idx + 1], serial_buffer[idx + 2]));

i know it still doesnt use all 60 leds but at least it takes up the whole LED strip which is wonderful.

waffle212121212: thanks for nothing.

You're welcome. That's all I can really offer someone who wants to learn by trial and error.

Been there waffle. I used to react the same way. Although it may seem like people are unhelpful and rude, when you stop and take the time to read (carefully) the replies and do a little research/reading (learning), it makes perfect sense in the end. And the replies although not helpful in writing your code for you, are definitely helpful in learning how to do it.

Divinity82: Been there waffle. I used to react the same way. Although it may seem like people are unhelpful and rude, when you stop and take the time to read (carefully) the replies and do a little research/reading (learning), it makes perfect sense in the end. And the replies although not helpful in writing your code for you, are definitely helpful in learning how to do it.

yeah man i get what you mean. i just wanted to do this small project and thats all. I wasnt trying to go all in but now i think im hooked into this after seeing the outcome. :)

waffle212121212: thanks for nothing. i figured it out by using this.

strip.setPixelColor(i*2, strip.Color(serial_buffer[idx], serial_buffer[idx + 1], serial_buffer[idx + 2]));

i know it still doesnt use all 60 leds but at least it takes up the whole LED strip which is wonderful.

For God's sake. This is not difficult.

/
/*---------------------------------------------------------*\
|                                                           |
|   WS2812B (NeoPixel) Serial Controlled LED Strip Driver   |
|     for use with Keyboard Visualizer VCUI                 |
|                                                           |
|   Adam Honse (calcprogrammer1) 1/22/2016                  |
|                                                           |
\*---------------------------------------------------------*/
#include 
#ifdef __AVR__
  #include 
#endif

#define PIN 3
const int NPIXELS = 60;
const int NBYTES = NPIXELS * 3;

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  // NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
 //  NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NPIXELS, PIN, NEO_RGB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.
unsigned char serial_buffer[NBYTES + 2];

void setup()
{
  Serial.begin(115200);
  strip.begin();
  strip.show();
}

void loop()
{
if( Serial.available() )
  {
  // normally we use memcpy for this
  for( int i = 0; i < NBYTES+1; i++ )
  {
    serial_buffer[i] = serial_buffer[i+1];
  }
  serial_buffer[NBYTES+1] = Serial.read();

  unsigned char sum = 0;
  for( int i = 0; i < NBYTES+1; i++ )
  {
    sum += serial_buffer[i];
  }
  //Test if valid write packet
  if(serial_buffer[0] == 0xAA && serial_buffer[NBYTES+1] == sum)
  {
    for( int i = 0; i < NPIXELS; i++ )
    {
      int idx = 1 + ( 3 * i );
      strip.setPixelColor(i, strip.Color(serial_buffer[idx], serial_buffer[idx+1], serial_buffer[idx+2]));
    }
    noInterrupts();
    strip.show();
    interrupts();
  }
  }
}

PaulMurrayCbr: For God's sake. This is not difficult.

/
/*---------------------------------------------------------*\
|                                                           |
|   WS2812B (NeoPixel) Serial Controlled LED Strip Driver   |
|     for use with Keyboard Visualizer VCUI                 |
|                                                           |
|   Adam Honse (calcprogrammer1) 1/22/2016                  |
|                                                           |
\*---------------------------------------------------------*/
#include 
#ifdef __AVR__
  #include 
#endif

define PIN 3

const int NPIXELS = 60; const int NBYTES = NPIXELS * 3;

// Parameter 1 = number of pixels in strip // Parameter 2 = Arduino pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: //  NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) //  NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)   // NEO_GRB    Pixels are wired for GRB bitstream (most NeoPixel products) //  NEO_RGB    Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) Adafruit_NeoPixel strip = Adafruit_NeoPixel(NPIXELS, PIN, NEO_RGB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input // and minimize distance between Arduino and first pixel.  Avoid connecting // on a live circuit...if you must, connect GND first. unsigned char serial_buffer[NBYTES + 2];

void setup() {   Serial.begin(115200);   strip.begin();   strip.show(); }

void loop() { if( Serial.available() )   {   // normally we use memcpy for this   for( int i = 0; i < NBYTES+1; i++ )   {     serial_buffer[i] = serial_buffer[i+1];   }   serial_buffer[NBYTES+1] = Serial.read();

  unsigned char sum = 0;   for( int i = 0; i < NBYTES+1; i++ )   {     sum += serial_buffer[i];   }   //Test if valid write packet   if(serial_buffer[0] == 0xAA && serial_buffer[NBYTES+1] == sum)   {     for( int i = 0; i < NPIXELS; i++ )     {       int idx = 1 + ( 3 * i );       strip.setPixelColor(i, strip.Color(serial_buffer[idx], serial_buffer[idx+1], serial_buffer[idx+2]));     }     noInterrupts();     strip.show();     interrupts();   }   } }

Well if it isnt difficult then your code should have worked but it didnt. None of my LEDs turn on with your code. LOL