Merci pour ton aide je vais tester cela mais j'ai essayer de contourner le problème en gardant le switch/case/break et donc appuyer à chaque fois pour faire clignoter les leds.
je te le met ci-dessous, la seul amélioration que je peut espérer c'est d'appuyer une fois pour faire clignotement les leds.
#include <Adafruit_NeoPixel.h>
#define BUTTON_PIN 2 // Digital IO pin connected to the button. This will be
// driven with a pull-up resistor so the switch should
// pull the pin to ground momentarily. On a high -> low
// transition the button press logic will execute.
#define PIXEL_PIN 6 // Digital IO pin connected to the NeoPixels.
#define PIXEL_COUNT 16
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
bool oldState = HIGH;
int showType = 0;
void setup() {
pinMode(BUTTON_PIN, INPUT);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
// Get current button state.
bool newState = digitalRead(BUTTON_PIN);
// Check if state changed from high to low (button press).
if (newState == LOW && oldState == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState = digitalRead(BUTTON_PIN);
if (newState == LOW) {
showType++;
if (showType > 9)
showType=0;
startShow(showType);
}
}
// Set the last button state to the old state.
oldState = newState;
}
void startShow(int i) {
switch(i){
case 0: colorWipe(strip.Color(255, 0, 0), 50); // Rouge
break;
case 1: colorWipe(strip.Color(127, 127, 127), 50); // Blanc
break;
case 2: colorWipe(strip.Color(255, 0, 0), 50); // Rouge
break;
case 3: colorWipe(strip.Color(127, 127, 127), 50); // Blanc
break;
case 4: colorWipe(strip.Color(255, 0, 0), 50); // Rouge
break;
case 5: colorWipe(strip.Color(127, 127, 127), 50); // Blanc
break;
case 6: colorWipe(strip.Color(255, 0, 0), 50); // Rouge
break;
case 7: colorWipe(strip.Color(127, 127, 127), 50); // Blanc
break;
case 8: colorWipe(strip.Color(255, 0, 0), 50); // Rouge
break;
case 9: colorWipe(strip.Color(127, 127, 127), 50); // Blanc
break;
case 10: colorWipe(strip.Color(255, 0, 0), 50); // Rouge
break;
case 11: colorWipe(strip.Color(127, 127, 127), 50); // Blanc
break;
case 12: colorWipe(strip.Color(255, 0, 0), 50); // Rouge
break;
case 13: colorWipe(strip.Color(127, 127, 127), 50); // Blanc
break;
case 14: colorWipe(strip.Color(255, 0, 0), 50); // Rouge
break;
case 15: colorWipe(strip.Color(127, 127, 127), 50); // Blanc
break;
case 16: colorWipe(strip.Color(255, 0, 0), 50); // Rouge
break;
}
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}