I am trying to write code for an automatic railroad crossing gates for my grandsons train table i built. I have no clue what i am doing. What i can say is im using 2 servos with external power 4 red leds that need to flash and a speaker for bell ding which i was hoping to use a sound file to play back my wire config is 2,3 for leds 2 servos 5,6 I also have a 10 second record-able device for train horn which uses push button for playback. i wanted to cut off the push button and use the arduino r3 to act as the push button pin 8. Also i will have 2 reed switches one to activate gates and lights and one to deactivate pins 4,7 this is what i have so far I get the lights to flash but im lost from there can some one help me write this code?
@@@@
int rd1LEDPin=2; //Declares rd1LED as int and set to 2
int rd2LEDPin=3; //declairs rd2LED as int and set to 3
int rd1onTime=250; //light 1 on time
int rd1offTime=250; // light 1 off time
int rd2onTime=250; //light 2 on time
int rd2offTime=250; // light 2 off time
const int REED_PIN = 4; // Pin connected to reed switch
const int REED_PIN = 7; // Pin connected to reed switch
const int LED_PIN = 13; // LED pin - active-high
void setup() {
pinMode(rd1LEDPin, OUTPUT);// sets the second pin for output
pinMode(rd2LEDPin, OUTPUT);// sets the third pin for output
Serial.begin(9600);
// Since the other end of the reed switch is connected to ground, we need
// to pull-up the reed switch pin internally.
pinMode(REED_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
digitalWrite(rd1LEDPin,HIGH); //turns led 1 on
digitalWrite(rd2LEDPin,LOW); // turns led 2 off
delay (rd1onTime); //wait
delay(rd2offTime); //wait
digitalWrite(rd1LEDPin,LOW); //turns led 1 off
digitalWrite(rd2LEDPin,HIGH);//turns led 2 on
delay (rd1offTime);// wait
delay(rd2onTime); //wait
int proximity = digitalRead(REED_PIN); // Read the state of the switch
if (proximity == LOW) // If the pin reads low, the switch is closed.
{
Serial.println("Switch closed");
digitalWrite(LED_PIN, HIGH); // Turn the LED on
}
else
{
digitalWrite(LED_PIN, LOW); // Turn the LED off
}