Hola, Feliz Navidad y Prospero año 2022
Se trata de poner un servo controlado por dos FC-51 y varios leds.
Los leds me funcionan pero he probado de activar los servos y no hay forma de que funcionen, en Google lo que encuentro no funcionan los códigos. Soy un poco novato y no veo la forma de que funcione, cualquier ayuda me vendría bien o sugerencia.
Gracias de antemano:
// barrera de tren con 2 led rojos intermitentes y 1 led verde fijo.
// cuando la "barrera" esta subida el led verde se enciende y se apagan los leds rojos
// cuando la "barrera" esta abajo el led verde se apaga y enciende los leds rojos
// la "barrera" esta por poner sera activada con 1 servo
int sensePin1=A0; // analog Pin A0 on the arduino
int sensePin2=A1; // analog Pin A1 on the arduino
int Red1=6; // light on crossing signal
int Red2=5; // light on crossing signal
int Verde=7;
void setup() {
Serial.begin(9600); // enables display of sensor output
pinMode(Red1,OUTPUT); //establishes pins as Output Pin
pinMode(Red2,OUTPUT);
pinMode(Verde,OUTPUT);
}
enum CROSSINGSTATES
{
ST_OFF,
ST_FLASHING1,
ST_FLASHING2,
ST_FLASHING3,
}; //identifies our 4 crossing states
CROSSINGSTATES crossingState=ST_OFF; // default state of the crossing
void loop() {
int valA1=analogRead(sensePin1); //reads and stores value of sensors
int valA2=analogRead(sensePin2);
switch(crossingState) // this is establishing where the program goes to when a sensor is read
{
case ST_OFF:
crossingoff(valA1, valA2);
break;
case ST_FLASHING1:
crossingflashing1(valA1, valA2);
break;
case ST_FLASHING2:
crossingflashing2(valA1, valA2);
break;
case ST_FLASHING3:
crossingflashing3(valA1, valA2);
break;
}
}
void crossingoff(int valA1, int valA2){
digitalWrite(Red1,LOW);
digitalWrite(Red2,LOW);
digitalWrite(Verde,HIGH);
if(valA1<500 && valA2>500){
crossingState=ST_FLASHING1; // if sensePin1 is tripped the program switches to Flashing 1
}
else if (valA1>500 && valA2<500){
crossingState=ST_FLASHING2; // if sensePin2 is tripped the program switches to Flashing 2
}
}
void crossingflashing1(int valA1, int valA2){
digitalWrite(Red1,HIGH);
digitalWrite(Red2,LOW);
digitalWrite(Verde,LOW);
delay(500); // This is half of the flashing signal and it goes for 0.5 seconds
digitalWrite(Red1,LOW);
digitalWrite(Red2,HIGH);
digitalWrite(Verde,LOW);
delay(500); // This will loop until a condition is met that would change it
if (valA1>500 && valA2<500){
crossingState=ST_FLASHING3;
}
}
void crossingflashing2(int valA1, int valA2){
digitalWrite(Red1,HIGH);
digitalWrite(Red2,LOW);
digitalWrite(Verde,LOW);
delay(500); // This is half of the flashing signal and it goes for 0.5 seconds
digitalWrite(Red1,LOW);
digitalWrite(Red2,HIGH);
digitalWrite(Verde,LOW);
delay(500); // This will loop until a condition is met that would change it
if (valA1<500 && valA2>500){
crossingState=ST_FLASHING3;
}
}
void crossingflashing3(int valA1, int valA2){
digitalWrite(Red1,HIGH);
digitalWrite(Red2,LOW);
digitalWrite(Verde,LOW);
delay(500); // This is half of the flashing signal and it goes for 0.5 seconds
digitalWrite(Red1,LOW);
digitalWrite(Red2,HIGH);
digitalWrite(Verde,LOW);
delay(500); // This will loop until a condition is met that would change it
if (valA1>500 && valA2>500){
crossingState=ST_OFF;
}
}


