Hola.
Estoy tratando que una tira de leds se comporte de una forma u otra en función de la entrada por 2 pines (PIN 2 y PIN 3) el problema que tengo es que uno de ellos (PIN 3) de vez en cuando envía tensión para verificar el circuito y crea falsos positivos.
He pensado en que solo se active la salida cuando PIN 3 esté por ejemplo 1 segundo activo, pero no logro hacerlo funcionar correctamente.
Este es el código que tengo a día de hoy.
#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_RGBW + 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;
unsigned long Tiempo;
void Turn_ON() // Car turn ON and all LED´s turn ON same time
{
for(int i=0;i<NUMPIXELS;i++)
{
strip.setPixelColor(i, strip.Color(000,002,000,000)); // LED´s Red.
}
strip.show(); // Update LED´s.
}
void Turn_OFF() // Car turn OFF and all LED´s turn OFF same time
{
for(int i=0;i<NUMPIXELS;i++)
{
strip.setPixelColor(i, strip.Color(000,000,000,000)); // LED´s OFF
}
strip.show(); // Update LED´s.
}
void Rear_Gear_ON() // Rear gear ON and all LED´s turn ON one by one
{
for(int i=0;i<NUMPIXELS;i++)
{
strip.setPixelColor(i, strip.Color(000,000,000,002)); // LED´s White
strip.show(); // Update LED´s.
}
}
void Rear_Gear_OFF() // Rear gear OFF and all LED´s turn OFF one by one (change to red one by one)
{
for(int i=0;i<NUMPIXELS;i++)
{
strip.setPixelColor(89-i, strip.Color(000,002,000,000)); // LED´s Red.
strip.show(); // Update LED´s.
}
}
void setup()
{
Tiempo=millis();
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)
{
// LED´s OFF
Turn_OFF();
}
else if (ESTADO_LUZ == HIGH && ESTADO_MARCHA == LOW)
{
// LED´s in RED
if (BANDERA == 1)
{
Rear_Gear_OFF();
BANDERA = 0;
}
else
{
Turn_ON();
}
}
else if (ESTADO_LUZ == HIGH && ESTADO_MARCHA == HIGH)
{
// LED´s in white
unsigned long tiempoTranscurrido=millis()-Tiempo;
if(tiempoTranscurrido>=1000)
{
Rear_Gear_ON();
BANDERA = 1;
}
else
{
Tiempo=millis();
Turn_ON();
}
}
}
Muchas gracias por vuestra ayuda.