Set neopixel strip to a colour with button press

Hi everyone,

I’m trying to get a code to run which sets a neopixel strip a certain colour when a button is pressed. I’ve connected the button no problem, but for some reason on being pressed it only sets one (the first) pixel the colour. What am I doing wrong in the code?

buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
for (int i=0; i<strip.numPixels()-1; i++) {
strip.setPixelColor(0, 0, 255,0);
strip.show();
delay(1000);
strip.clear();
}

(Sorry, I am very new to this so it may be a very basic question!)

Would appreciate any help.

Check the syntax for the setPixelColor function. First argument is the position in the pixel strip. You have 0 in your sketch so you only ever change the colour of the first pixel.

I'm not sure you want/need that strip.clear() in the for loop, by the way.

I'm not sure you want/need that strip.clear() in the for loop, by the way.

I AM sure that you don't.