Advertisement
kartonman

bells basic error?

Oct 5th, 2021 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. /*Warning bells sensor sontrolled." */
  2.  
  3. #define East A0 //connects to output pin of IR sensor East
  4. #define West A1 //connects to output pin of IR sensor West
  5. #define Control 8 /* connect to play on DF player If it goes high the bells start playing. */
  6. int valcontrol = 0;
  7. void setup() {
  8. Serial.begin(9600);
  9. pinMode(East, INPUT);
  10. pinMode(West, INPUT);
  11. pinMode(Control, OUTPUT);
  12.  
  13. }
  14. void loop() {
  15.  
  16. int valEast = digitalRead(East);
  17. int valWest = digitalRead(West);
  18. //if bells are not ringing and neither sensor is tripprd, meaning a train has not enter the crossing,
  19. //the bells do not ring.
  20. if (Control, LOW){
  21. if ((valWest == HIGH) || (valEast == HIGH))
  22. //if a train passes one of the sensors, the bells commence ringing. If it is longer than the distance between
  23. // the sensore, the bells continue to ring.
  24. {
  25. digitalWrite(Control, HIGH);
  26. } else {
  27. digitalWrite(Control, LOW);
  28. }}
  29. //the bells are now ringing. a short train will be between the sensors but the bells should continue to ring.
  30. // even though no sensor detects the train. so:
  31.  
  32. if (Control, HIGH)
  33. {
  34. if ((valWest == HIGH) && (valEast == HIGH))
  35. {
  36. digitalWrite(Control, HIGH);
  37. }
  38. else
  39. {
  40. if ((valWest == LOW) || (valEast == LOW))
  41. {
  42.  
  43. digitalWrite(Control, LOW);
  44. }}
  45. } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement