Estoy haciendo un proyecto en el que controlo una tira de 8 leds WS2812 usando un botón para cada led (8 botones) mientras que cuando no se esté presionando ningún botón continue una animación, también que si presiono una combinación de botones al mismo tiempo hagan otra animación, hasta el momento he logrado que al presionar el primer botón el primer led prenda de color verde pero en mis intentos de usar otro botón para otro led este se queda trabado o funciona de manera erratica, el arduino que tengo es un mega para probar pero el proyecto lo voy a pasar a un pro mini (no cuento con el en este momento pues apenas viene en camino)
#include <Adafruit_NeoPixel.h>
#define BUTTON_PIN 2
//#define BUTTON_PINDOS 3
#define PIXEL_PIN 6
#define PIXEL_COUNT 8
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_PULLUP);
strip.begin();
uint16_t i, j;
}
void loop() {
//void rainbow
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
bool newState = digitalRead(BUTTON_PIN);
if (newState == LOW && oldState == HIGH) {
newState = digitalRead(BUTTON_PIN);
if (newState == LOW) {
showType = 1;
startShow(showType);
}
}
// bool newState2 = digitalRead(BUTTON_PINDOS);
// if (newState2 == LOW && oldState == HIGH) {
//
// newState2 = digitalRead(BUTTON_PINDOS);
// if (newState2 == LOW) {
// showType = 2;
// startShow(showType);
// }
// }
strip.show();
delay(250);
}
}
void startShow(int i) {
switch(i){
case 1: strip.setPixelColor(0, strip.Color(0,255,0));
showType=0;
break;
case 2: strip.setPixelColor(1, strip.Color(255,0,0));
showType=0;
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(10);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
Gracias por su atención!