0

LEDs are not properly reflecting the code
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

LEDs are not properly reflecting the code

by Quaseedodo on Thu May 16, 2019 9:09 pm

Hello. I'm at a loss and am ready to give up. I want my lights (2846) to flash a white color but despite what code I type in and send, the lights do not follow the corresponding commands. For example, I wanted my lights to fade in and out of the colors red, green, and blue.
Code: Select all | TOGGLE FULL SIZE
void loop() {
   RGBLoop();
}

void RGBLoop(){
  for(int j = 0; j < 3; j++ ) {
    //Fade IN
    for(int k = 0; k < 256; k++) {
      switch(j) {
        case 0: setAll(k,0,0); break;
        case 1: setAll(0,k,0); break;
        case 2: setAll(0,0,k); break;
      }
      showStrip();
      delay(3);
    }
    //Fade OUT
    for(int k = 255; k >=0; k--) {
      switch(j) {
        case 0: setAll(k,0,0); break;
        case 1: setAll(0,k,0); break;
        case 2: setAll(0,0,k); break;
      }
      showStrip();
      delay(3);
    }
  }
}

void showStrip() {
  #ifdef ADAFRUIT_NEEOPIXEL_H
    //Neopixel
    strip.show();
  #endif
}


void setPixel(int Pixel, byte red, byte green, byte blue) {
  #ifdef ADAFRUIT_NEOPIXEL_H
    //Neopixel
    strip.setPixelColor(Pixel, strip.Color(red, green, blue));
    #endif
}

void setAll(byte red, byte green, byte blue) {
  for(int i=0; i < 7; i++) {
    setPixel(i, red, green, blue);
  }

  showStrip();


However, when I enter this, my strip does not fade in and out. Only two pixels are lit at the end and there is no animation within the strip.
Last edited by franklin97355 on Thu May 16, 2019 11:51 pm, edited 1 time in total.
Reason: Please use code tags when posting code or logs to the forums. It preserves formatting and makes it easier for everyone to read the code. Click the code button above the reply box and past your code between the tags created.

Quaseedodo
 
Posts: 9
Joined: Wed May 08, 2019 9:37 am

Re: LEDs are not properly reflecting the code

by adafruit_support_bill on Fri May 17, 2019 5:45 am

Please post your complete code.

Also please post photos showing your soldering and connections.

adafruit_support_bill
 
Posts: 74627
Joined: Sat Feb 07, 2009 10:11 am

Re: LEDs are not properly reflecting the code

by kcl1s on Fri May 17, 2019 6:02 am

I always find it best to first work with known good code to rule out hardware issues. What happens when you run the strandtest example adjusted to your number of pixels?

Fellow hobbyist
Keith

kcl1s
 
Posts: 1290
Joined: Tue Aug 30, 2016 12:06 pm

Re: LEDs are not properly reflecting the code

by Disciple on Sat May 18, 2019 6:07 pm

From my unassailable position of complete ignorance with regard to your project,
my eyes spy what looks like a typo in the showStrip() function,
and I think setAll() needs one more } .
FWIW, that's all I got.

Hallelujah!
Disciple

Disciple
 
Posts: 684
Joined: Tue Jan 06, 2015 8:13 pm

Re: LEDs are not properly reflecting the code

by Quaseedodo on Sun May 19, 2019 9:33 am

kcl1s wrote:I always find it best to first work with known good code to rule out hardware issues. What happens when you run the strandtest example adjusted to your number of pixels?

Fellow hobbyist
Keith



Hey! When I do a strandtest with the Neopixel strip, it goes through a series of animations but it does not complete a full rainbow. However, with my Neopixel Jewel, the LEDs respond appropriately with the exact same code. They go through the spectrum of the rainbow and can be animated with one specific color. The strip simply goes through a few colors and when instructed to do a colorwipe with a specific color, on the first and last pixel reflect that color. All other pixels do a different color.

Quaseedodo
 
Posts: 9
Joined: Wed May 08, 2019 9:37 am

Re: LEDs are not properly reflecting the code

by kcl1s on Sun May 19, 2019 12:58 pm

Quaseedodo wrote: The strip simply goes through a few colors and when instructed to do a colorwipe with a specific color, on the first and last pixel reflect that color. All other pixels do a different color.


That sounds like you may have an RGBW strip. If the pixels have a large half moon shaped yellow segment they are RGBW. https://www.adafruit.com/product/2759

If so use the RGBW strandtest and see what you get.

Keith

kcl1s
 
Posts: 1290
Joined: Tue Aug 30, 2016 12:06 pm

Re: LEDs are not properly reflecting the code

by Blueshark on Sun May 19, 2019 8:13 pm

@ Quaseedodo


There are problems with your code, I ran the standard Neopixel Strandtest with you code see below and it has problems....

Code: Select all | TOGGLE FULL SIZE
   
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 6

// 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)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, PIN, NEO_GRB + 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.

void setup() {
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  //#if defined (__AVR_ATtiny85__)
    //if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  //#endif
  // End of trinket special code


  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}


void loop() {
   RGBLoop();
}

void RGBLoop(){
  for(int j = 0; j < 3; j++ ) {
    //Fade IN
    for(int k = 0; k < 256; k++) {
      switch(j) {
        case 0: setAll(k,0,0); break;
        case 1: setAll(0,k,0); break;
        case 2: setAll(0,0,k); break;
      }
      showStrip();
      delay(3);
    }
    //Fade OUT
    for(int k = 255; k >=0; k--) {
      switch(j) {
        case 0: setAll(k,0,0); break;
        case 1: setAll(0,k,0); break;
        case 2: setAll(0,0,k); break;
      }
      showStrip();
      delay(3);
    }
  }
}

void showStrip() {
  #ifdef ADAFRUIT_NEEOPIXEL_H
    //Neopixel
    strip.show();
  #endif
}


void setPixel(int Pixel, byte red, byte green, byte blue) {
  #ifdef ADAFRUIT_NEOPIXEL_H
    //Neopixel
    strip.setPixelColor(Pixel, strip.Color(red, green, blue));
    #endif
}

void setAll(byte red, byte green, byte blue) {
  for(int i=0; i < 7; i++) {
    setPixel(i, red, green, blue);
  }
}

  showStrip();




this is the error message....
Code: Select all | TOGGLE FULL SIZE
Arduino: 1.8.9 (Windows 10), Board: "Adafruit Metro"

strandtest:85:14: error: expected constructor, destructor, or type conversion before ';' token

   showStrip();

              ^

exit status 1
expected constructor, destructor, or type conversion before ';' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.




I think you still need to work on it.

Are you powering your Neopixels with an added powersupply?

post pictures of your setup, board, and Neopiel strip.


Cheers...

Blueshark
 
Posts: 142
Joined: Thu Dec 21, 2017 7:19 pm

Re: LEDs are not properly reflecting the code

by Quaseedodo on Sun May 19, 2019 8:19 pm

kcl1s wrote:
Quaseedodo wrote: The strip simply goes through a few colors and when instructed to do a colorwipe with a specific color, on the first and last pixel reflect that color. All other pixels do a different color.


That sounds like you may have an RGBW strip. If the pixels have a large half moon shaped yellow segment they are RGBW. https://www.adafruit.com/product/2759

If so use the RGBW strandtest and see what you get.

Keith



My god...thank you so much! This solution finally proved to be the one that worked. What's the difference between a regular strandtest vs the RGBWstrandtest? Is it wrong to assume all of their digital LED strips are the same then?

Quaseedodo
 
Posts: 9
Joined: Wed May 08, 2019 9:37 am

Re: LEDs are not properly reflecting the code

by Quaseedodo on Sun May 19, 2019 8:20 pm

Blueshark wrote:@ Quaseedodo


There are problems with your code, I ran the standard Neopixel Strandtest with you code see below and it has problems....

Code: Select all | TOGGLE FULL SIZE
   
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 6

// 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)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, PIN, NEO_GRB + 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.

void setup() {
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  //#if defined (__AVR_ATtiny85__)
    //if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  //#endif
  // End of trinket special code


  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}


void loop() {
   RGBLoop();
}

void RGBLoop(){
  for(int j = 0; j < 3; j++ ) {
    //Fade IN
    for(int k = 0; k < 256; k++) {
      switch(j) {
        case 0: setAll(k,0,0); break;
        case 1: setAll(0,k,0); break;
        case 2: setAll(0,0,k); break;
      }
      showStrip();
      delay(3);
    }
    //Fade OUT
    for(int k = 255; k >=0; k--) {
      switch(j) {
        case 0: setAll(k,0,0); break;
        case 1: setAll(0,k,0); break;
        case 2: setAll(0,0,k); break;
      }
      showStrip();
      delay(3);
    }
  }
}

void showStrip() {
  #ifdef ADAFRUIT_NEEOPIXEL_H
    //Neopixel
    strip.show();
  #endif
}


void setPixel(int Pixel, byte red, byte green, byte blue) {
  #ifdef ADAFRUIT_NEOPIXEL_H
    //Neopixel
    strip.setPixelColor(Pixel, strip.Color(red, green, blue));
    #endif
}

void setAll(byte red, byte green, byte blue) {
  for(int i=0; i < 7; i++) {
    setPixel(i, red, green, blue);
  }
}

  showStrip();




this is the error message....
Code: Select all | TOGGLE FULL SIZE
Arduino: 1.8.9 (Windows 10), Board: "Adafruit Metro"

strandtest:85:14: error: expected constructor, destructor, or type conversion before ';' token

   showStrip();

              ^

exit status 1
expected constructor, destructor, or type conversion before ';' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.




I think you still need to work on it.

Are you powering your Neopixels with an added powersupply?

post pictures of your setup, board, and Neopiel strip.


Cheers...



I do plan to use a LiPo battery with the setup. But, I simply needed to use the RGBWstrandtest sketch to make it work. I think I'll use that sketch as a basis for what I want to do. Thank you so much for your help!

Quaseedodo
 
Posts: 9
Joined: Wed May 08, 2019 9:37 am

Re: LEDs are not properly reflecting the code

by kcl1s on Sun May 19, 2019 9:07 pm

My god...thank you so much! This solution finally proved to be the one that worked. What's the difference between a regular strandtest vs the RGBWstrandtest? Is it wrong to assume all of their digital LED strips are the same then?

RGBW pixels have a 4th color on each pixel (red, green, blue, and white) and your code has add a value for the white element for each setPixelColor for a total of 4. The way Neopixels work is each pixel pulls off the 3 or 4 data chunks it needs and passes the rest down the strip to the next pixel and the process repeats. When you feed 3 chunk (RGB) data to a RGBW strip it pulls off 4 chunks so the color info gets scrambled.

This extensive guide has all the info on the different Neopixel products Adafruit sells. https://learn.adafruit.com/adafruit-neopixel-uberguide/

Keith

kcl1s
 
Posts: 1290
Joined: Tue Aug 30, 2016 12:06 pm

Please be positive and constructive with your questions and comments.