Adafruit NeoPixel Help

Hello! I’m having difficulty with this code:

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif
int button1 = 2;
int button2 = 3;
int button3 = 7;
#define PIN 8

Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);

  #if defined (__AVR_ATtiny85__)
    if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  #endif
  strip.begin();
  strip.show(); // initialize all pixels to 'off'
}

void loop(){
  int val1 = digitalRead(button1);
  int val2 = digitalRead(button2);
  int val3 = digitalRead(button3);
  while ((val1 == HIGH) && (val2 == LOW) && (val3 == LOW)) {
    strip.setPixelColor(255, 0, 0);
    strip.show();
  }
  while ((val1 == LOW) && (val2 == HIGH) && (val3 == LOW)){
    strip.setPixelColor(0, 255, 0);
    strip.show();
  }
  while ((val1 == LOW) && (val2 == LOW) && (val3 == HIGH)) {
    strip.setPixelColor(0, 0, 255);
  }
}

It’s returning an error message that says,
‘strip’ does not name a type
on this line:

  strip.show(); // initialize all pixels to 'off'

I honestly do not understand it at all. Does anyone have any ideas? :disappointed_relieved:

It looks like you have accidentally deleted

void setup() {

I’ve looked back at the example codes and changed to this:

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif
int button1 = 2;
int button2 = 3;
int button3 = 7;
#define PIN 8
#define NUMPIXELS 16

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 5; // delay
void setup() {
  #if defined (__AVR_ATtiny85__)
    if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  #endif
  pixels.begin();
}

void loop(){
  int val1 = digitalRead(button1);
  int val2 = digitalRead(button2);
  int val3 = digitalRead(button3);
   for(int i=0;i<NUMPIXELS;i++){
    while ((val1 == HIGH) && (val2 == LOW) && (val3 == LOW)) {
      pixels.setPixelColor(i, pixels.Color(255,0,0));
      pixels.show();
      delay(delayval);
    }
    while ((val1 == LOW) && (val2 == HIGH) && (val3 == LOW)){
      pixels.setPixelColor(i, pixels.Color(0,255,0));
      pixels.show();
      delay(delayval);
    }
    while ((val1 == LOW) && (val2 == LOW) && (val3 == HIGH)) {
      pixels.setPixelColor(i, pixels.Color(0,0,255));
      pixels.show();
      delay(delayval);
    }
   }
}

But now, the first light is blue and the next 15 are off. The 14 after that are green. Does anyone know why this is?

I also tried this:

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif
int button1 = 2;
int button2 = 3;
int button3 = 7;
#define PIN 8
#define NUMPIXELS 16

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 5; // delay
void setup() {
  #if defined (__AVR_ATtiny85__)
    if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  #endif
  pixels.begin();
}

void loop(){
  int val1 = digitalRead(button1);
  int val2 = digitalRead(button2);
  int val3 = digitalRead(button3);
    while ((val1 == HIGH) && (val2 == LOW) && (val3 == LOW)) {
         for(int i=0;i<NUMPIXELS;i++){
      pixels.setPixelColor(i, pixels.Color(255,0,0));
      pixels.show();
      delay(delayval);
         }
    }
    while ((val1 == LOW) && (val2 == HIGH) && (val3 == LOW)){
        for(int i=0;i<NUMPIXELS;i++){
      pixels.setPixelColor(i, pixels.Color(0,255,0));
      pixels.show();
      delay(delayval);
        }
    }
    while ((val1 == LOW) && (val2 == LOW) && (val3 == HIGH)) {
         for(int i=0;i<NUMPIXELS;i++){
      pixels.setPixelColor(i, pixels.Color(0,0,255));
      pixels.show();
      delay(delayval);
    }
   }
}

The first 16 lights are blue and the next 14 are green.