Good afternoon evereyone. My name is Ron and I am working on a lego train project.
What I am doing now is working on a Railroad crossing.
when the barrier goes down , i want a led flashing.
i would apreciate some help
// Servo aansturing tbv slagboom
#include <Servo.h>
Servo myservo; // create servo object to control a servo
const int ledPin = 12; // the number of the LED pin
const int buttonPin1 = 2; // the number of the pushbutton pin
const int buttonPin2 = 3; // the number of the pushbutton pin
//const int reedPin1 = 3; // the number of the pushbutton pin
//const int reedPin2 = 4; // the number of the pushbutton pin
int pos = 0; // variable to store the servo position
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0; // variable for reading the pushbutton status
int reedState1 = 0; // variable for reading the pushbutton status
int reedState2 = 0; // variable for reading the pushbutton status
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(buttonPin1, INPUT); // initialize the pushbutton pin as an input
pinMode(buttonPin2, INPUT); // initialize the pushbutton pin as an input
// pinMode(reedPin1, INPUT); // initialize the pushbutton pin as an input
// pinMode(reedPin2, INPUT); // initialize the pushbutton pin as an input
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output:
}
void loop() {
buttonState1 = digitalRead(buttonPin1); // read the state of the pushbutton value:
// reedState1 = digitalRead(reedPin1); // read the state of the pushbutton value:
if (buttonState1 == HIGH ) { // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
for (pos = 0; pos <= 85; pos += 1) { //start positie slagboom hoog.goes from 0 degrees to 75 degrees in steps of 1 degree
digitalWrite(ledPin, HIGH); //led aan
myservo.write(pos); //tell servo to go to position in variable 'pos'
delay(75); //waits 15ms for the servo to reach the position
digitalWrite(ledPin, LOW);
}
}
buttonState2 = digitalRead(buttonPin2); // read the state of the pushbutton value:
// reedState2 = digitalRead(reedPin2); // read the state of the pushbutton value:
if (buttonState2 == HIGH ) { // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
for (pos = 85; pos >= 0; pos -= 1) { //goes from 90 degrees to 0 degrees
digitalWrite(ledPin, LOW); //led gaat uit
myservo.write(pos); //tell servo to go to position in variable 'pos'
delay(75); //waits 15ms for the servo to reach the position
}
}
}