The first version of the project works correctly, I have decided to modify some small details, depending on the input will change color to another as follows:
LED off
A = + red color (simultaneous ignition)
A = + and B = + white color (progressive ignition)
A = + (after white) change from white to progressive red
LED off (simultaneous shutdown)
The case is that I want that if B never happens to + the LEDs turn on and off simultaneously but the B ignition is progressive (this is OK) and the step from B to A is also progressive (here I am stuck).
I have thought to introduce a variable "BANDERA" that if it is "0" A always turn on and off simultaneously but if "BANDERA" at some point becomes "+" the shutdown is progressive.
#include <Adafruit_NeoPixel.h>
// Pines totales tira
#define NUMPIXELS 90
// Puerto de datos tira
#define PIN 4
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); //Define el objeto pixels que es la tira de leds
const int LUZ_ENCENDIDA=2;
const int MARCHA_ATRAS=3;
const int SALIDA=4;
int ESTADO_LUZ;
int ESTADO_MARCHA;
int BANDERA = 0;
void setup()
{
strip.begin();
pinMode(LUZ_ENCENDIDA,INPUT);
pinMode(MARCHA_ATRAS,INPUT);
pinMode(SALIDA,OUTPUT);
}
void loop()
{
ESTADO_LUZ=digitalRead(LUZ_ENCENDIDA);
ESTADO_MARCHA=digitalRead(MARCHA_ATRAS);
if (ESTADO_LUZ==LOW & ESTADO_MARCHA==LOW) // Todo apagado
{
for(int i=0;i<NUMPIXELS;i++)
{
strip.setPixelColor(i, strip.Color(000,000,000)); // LED´s Apagados
}
strip.show(); // Simultaneo
}
if (ESTADO_LUZ==HIGH & ESTADO_MARCHA==LOW) // Luz ambiente encendida
{ if (BANDERA==1)
for(int i=0;i<NUMPIXELS;i++)
{
strip.setPixelColor(i, strip.Color(200,000,000)); // LED´s Rojo
strip.show(); // Progresivo.
}
else
for(int i=0;i<NUMPIXELS;i++)
{
strip.setPixelColor(i, strip.Color(200,000,000)); // LED´s Rojo
}
strip.show(); // Simultaneo
}
if (ESTADO_LUZ==HIGH & ESTADO_MARCHA==HIGH) // Marcha atrás puesta
{
for(int i=0;i<NUMPIXELS;i++)
{
strip.setPixelColor(89-i, strip.Color(150,150,150)); // LED´s Blanco 255 seria brillo máximo
strip.show(); // Progresivo.
}
BANDERA==1;
}
}