Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Warning bells sensor sontrolled." */
- #define East A0 //connects to output pin of IR sensor East
- #define West A1 //connects to output pin of IR sensor West
- #define Control 8 /* connect to play on DF player If it goes high the bells start playing. */
- int valcontrol = 0;
- void setup() {
- Serial.begin(9600);
- pinMode(East, INPUT);
- pinMode(West, INPUT);
- pinMode(Control, OUTPUT);
- }
- void loop() {
- int valEast = digitalRead(East);
- int valWest = digitalRead(West);
- //if bells are not ringing and neither sensor is tripprd, meaning a train has not enter the crossing,
- //the bells do not ring.
- if (Control, LOW){
- if ((valWest == HIGH) || (valEast == HIGH))
- //if a train passes one of the sensors, the bells commence ringing. If it is longer than the distance between
- // the sensore, the bells continue to ring.
- {
- digitalWrite(Control, HIGH);
- } else {
- digitalWrite(Control, LOW);
- }}
- //the bells are now ringing. a short train will be between the sensors but the bells should continue to ring.
- // even though no sensor detects the train. so:
- if (Control, HIGH)
- {
- if ((valWest == HIGH) && (valEast == HIGH))
- {
- digitalWrite(Control, HIGH);
- }
- else
- {
- if ((valWest == LOW) || (valEast == LOW))
- {
- digitalWrite(Control, LOW);
- }}
- } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement