Hola amigos
Espero poder explicarme bien.
Soy relativamente nuevo usando Arduino y por Internet encontré este código.
Lo que deseo es controlar 16 leds WS2812B y tengo este código y lo que me gustaría agregar es un push button y que antes de pulsar el botón todos los leds estén apagados y que al pulsar el botón inicie un efecto (el código consta de 4 diferentes secuancias/efectos) y se mantenga activo y que al pulsar de nuevo el botón ahora se active otro efecto y así sucesivamente y al final cuando este activo la secunacia 4 al pulsar el botón se apaguen todos los leds.
¿Alguien que me pueda ayudar sobre que debo agregar o quitar del código?
//Proyecto #18 Bicilights
//Creado el: 25/Marzo/2020
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN1 9 ////Conectar resistencia de 330 a 470 homs a DIN del 1er Led WS2812B
Adafruit_NeoPixel strip = Adafruit_NeoPixel(16,PIN1, NEO_GRB + NEO_KHZ800); ////Total de led conectados
void setup() {
strip.begin();
strip.setBrightness(150); // Ajuste de Brillo de todos los leds
strip.show();
}
void loop() {
/*
* For strip.Color(R, G, B), use 0-255 to set intensity
* for each color (R)ed, (G)reen, (B)lue
*
* The last number is a delay 0-255 range.
*/
// These are left/right signals SECUENCIA 1
/// R G B Velocidad en ms (ms = milisegundos)
ArrowLeft(strip.Color(200, 200, 0), 100); // Amarillo
ArrowRight(strip.Color(255, 255, 255), 100); //White
ArrowLeft(strip.Color(255, 0, 0), 100); // Red
ArrowLeft(strip.Color(255, 255, 255), 30); // White
ArrowRight(strip.Color(200, 200, 0), 30); // Amarillo
ArrowLeft(strip.Color(255, 0, 0), 30); // Red
ArrowLeft(strip.Color(255, 255, 255), 70); // White
ArrowRight(strip.Color(200, 200, 0), 70); // Amarillo
ArrowLeft(strip.Color(255, 0, 0), 70); // Red
ClearLights();
delay(50);
// These are side to side or wig/wag SECUENCIA 2
WigWag(strip.Color(255, 0, 0), 200); // Red
WigWag(strip.Color(0, 0, 255), 63); // Blue faster
WigWag(strip.Color(0, 0, 255), 127); // Blue medium
WigWag(strip.Color(0, 0, 255), 255); // Blue slowest
WigWag(strip.Color(255, 255, 0), 400); // Amarillo Low
WigWag(strip.Color(255, 0, 0), 63); // Red faster
ClearLights();
delay(50);
// This is a 2 color wigwag SECUENCIA 3
WigWag2(strip.Color(200, 200, 0), strip.Color(255, 255, 255), 200); // Amarillo y Blanco
WigWag2(strip.Color(200, 200, 200), strip.Color(200, 0, 0), 200); // Blanco y Rojo
WigWag2(strip.Color(255, 0, 0), strip.Color(200, 200, 0), 200); // Rojo y Amarillo
ClearLights();
delay(50);
// Blinks the outer most lights SECUENCIA 4
BlinkOuter(strip.Color(200, 200, 0), 200); //Amarillo
BlinkOuter(strip.Color(200, 200, 0), 50); //Amarillo faster
BlinkOuter(strip.Color(255, 0, 0), 200); //Red
BlinkOuter(strip.Color(255, 0, 0), 50); //Red faster
BlinkOuter(strip.Color(255, 255, 255), 200); //White
BlinkOuter(strip.Color(255, 255, 255), 50); //White faster
BlinkOuter(strip.Color(255, 0, 0), 200); //Red
BlinkOuter(strip.Color(200, 200, 0), 50); //Amarillo faster
ClearLights();
delay(50);
}
void ArrowRight(uint32_t c, uint8_t wait) {
for (int j = 0; j < 4; j++) { // The j<# determines how many cycles
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, 0);
}
strip.show();
delay(wait);
}
}
void ArrowLeft(uint32_t c, uint8_t wait) {
for (int j = 0; j < 4; j++) { // The j<# determines how many cycles
for (uint16_t i = strip.numPixels(); i + 1 > 0 ; i--) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
for (uint16_t i = strip.numPixels(); i + 1 > 0 ; i--) {
strip.setPixelColor(i, 0);
}
strip.show();
delay(wait);
}
}
void WigWag(uint32_t c, uint8_t wait) {
for (int j = 0; j < 10; j++) { // The j<# determines how many cycles
for (int i = 0; i < strip.numPixels(); i = i + 1) {
strip.setPixelColor(i, c);
}
for (int i = (strip.numPixels() / 2); i < strip.numPixels(); i = i + 1) {
strip.setPixelColor(i, 0);
}
strip.show();
delay(wait);
for (int i = 0; i < strip.numPixels(); i = i + 1) {
strip.setPixelColor(i, 0);
}
for (int i = (strip.numPixels() / 2); i < strip.numPixels(); i = i + 1) {
strip.setPixelColor(i, c);
}
strip.show();
delay(wait);
}
}
void WigWag2(uint32_t c, uint32_t c2, uint8_t wait) {
for (int j = 0; j < 20; j++) { // The j<# determines how many cycles
for (int i = 0; i < strip.numPixels(); i = i + 1) {
strip.setPixelColor(i, c);
}
for (int i = (strip.numPixels() / 2); i < strip.numPixels(); i = i + 1) {
strip.setPixelColor(i, 0);
}
strip.show();
delay(wait);
for (int i = 0; i < strip.numPixels(); i = i + 1) {
strip.setPixelColor(i, 0);
}
for (int i = (strip.numPixels() / 2); i < strip.numPixels(); i = i + 1) {
strip.setPixelColor(i, c2);
}
strip.show();
delay(wait);
}
}
void ClearLights() {
for (int i = 0; i < strip.numPixels(); i = i + 1) {
strip.setPixelColor(i, 0); //turn every pixel off
}
strip.show();
}
void BlinkOuter(uint32_t c, uint8_t wait) {
for (int j = 0; j < 10; j++) { // The j<# determines how many cycles
strip.setPixelColor(strip.numPixels() - 1, 0);
strip.setPixelColor(strip.numPixels() - 4, 0);
strip.setPixelColor(strip.numPixels() - 5, 0);
strip.setPixelColor(strip.numPixels() - 8, 0);
strip.setPixelColor(8, 8);
strip.show();
delay(wait);
strip.setPixelColor(strip.numPixels() - 1, c);
strip.setPixelColor(strip.numPixels() - 4, c);
strip.setPixelColor(strip.numPixels() - 5, c);
strip.setPixelColor(strip.numPixels() - 8, c);
strip.setPixelColor(8, 8);
strip.show();
delay(wait);
}
}