Have exhausted everything I can think of...

I am helping a student and would appreciate new eyes on this. I cannot figure out what I’m missing.

I have a simple strip of 3 neopixels that I am trying to cycle through colors. I found and tested the blue function but when I replicated it for the other colors (red, green, yellow), the strip only shows blue. Thank you.

///code from https://www.arduinoplatform.com/arduino-visual-output/controlling-and-powering-neopixels-with-arduino/
///http://www.highschoolmaker.com/electronics-with-micro-controllers/chapter-8-neopixels/8-2-create-some-neopixel-functions/

#include <Adafruit_NeoPixel.h>
 
#define PIN 10
#define LEDS 3

Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDS, PIN, NEO_GRB + NEO_KHZ800);
 
void setup() {
  strip.begin();
  strip.show();  // Initialize all pixels to 'off'
}
 
void loop() {
   blue();
    delay(1000);
    
   red();
    delay(1000);
  
   green();
    delay(1000);

   yellow();
    delay(1000);
  
}

void red()
  {
  for(int i = 0; i < LEDS; i++){
    strip.setPixelColor(i, (255,0,0)); 
  }
  strip.show();
  }

void blue()
  {
  for(int i = 0; i < LEDS; i++){
    strip.setPixelColor(i, (0,0,255)); 
  }
  strip.show();
  }
  
  
void green()
  {
  for(int i = 0; i < LEDS; i++){
    strip.setPixelColor(i, (0,255,0)); 
  }
  strip.show();
  }
  
void yellow()
  {
  for(int i = 0; i < LEDS; i++){
    strip.setPixelColor(i,(255,215,0)); 
  }
  strip.show();
  }

You’ve written the colors wrong. Lose the parentheses.

setPixelColor(i, 215, 230, 200);

HTH

a7

Presuming you are using the Arduino IDE, set File>Preferences>Compiler warnings to "All" and you will see a few instances of the following:

/home/jdbarney/Arduino/forumtest/forumtest.ino: In function 'void red()':
/home/jdbarney/Arduino/forumtest/forumtest.ino:34:34: warning: left operand of comma operator has no effect [-Wunused-value]
     strip.setPixelColor(i, (255, 0, 0));
                                  ^
/home/jdbarney/Arduino/forumtest/forumtest.ino:34:37: warning: right operand of comma operator has no effect [-Wunused-value]
     strip.setPixelColor(i, (255, 0, 0));
                                     ^

You've written the colors wrong. Lose the parentheses.

setPixelColor(i, 215, 230, 200);

You can also use .Color() to convert the RGB values into a single uint32_t, handy if you want to store the colors in a variable or array.

    strip.setPixelColor(i, strip.Color(255, 0, 0));

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.