neopixel button control (temporarily stop changing the color)

Hello :slight_smile:
I implemented the neopixel color changing slowly using the rainbow function, but I want to control the color change using two buttons.

  • Button 1: Keep the color at the moment of pressing (= temporarily stop changing the color)
  • Button 2: Adjusts the overall brightness (0%, 20%, ..., 100%) 6 phase

The rainbowCycle function changes each LED color to a different timing like a wave.
But only rainbow seems to be enough.

If you have any experience please help.
Thank you :slight_smile:

#include <Adafruit_NeoPixel.h>
#define PIN 12

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

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

void loop() {
rainbow(20);
rainbowCycle(200);
}

void rainbow(uint8_t wait) {
uint16_t i, j;

for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}

void rainbowCycle(uint8_t wait) {
uint16_t i, j;

for(j=0; j<256*5; j++) {
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}

uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}

Look at your rainbow() function. Do you see any code there to read the state of a switch? I don't.

Look at your rainbowCycle() function. Do you see any code there to read the state of a switch? I don't.

Look at your loop() function. Do you see any code there to read the state of a switch? I don't.

I want to control the color change using two buttons.

Well, go right ahead.