Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. //assigning each pin a name to make it easier for both use in the program, and change the pin used in the future
  2. // using const unsigned char as this counts 0-255 and has a storage value of 1 byte, const so they are read-only
  3.  
  4. const unsigned char senAA1 = 05
  5. const unsigned char senAA2 = 06
  6. const unsigned char senAB1 = 07
  7. const unsigned char senAB2 = 08
  8. const unsigned char senBB1 = 09
  9. const unsigned char senBB2 = 10
  10. const unsigned char relOut1 = 15
  11.  
  12. void setup() {
  13.  
  14. //declaring whether the pins used are input or output
  15.  
  16. pinMode(senAA1, INPUT);
  17. pinMode(senAA2, INPUT);
  18. pinMode(senAB1, INPUT);
  19. pinMode(senAB2, INPUT);
  20. pinMode(senBB1, INPUT);
  21. pinMode(senBB2, INPUT);
  22. pinMode(relOut1, OUTPUT);
  23.  
  24. //creating variables and assigning the initial values for total axles in and total axles out
  25. //also creating a variable for the total number of axles
  26.  
  27. unsigned char nIn = 0;
  28. unsigned char nOut = 0;
  29. unsigned char nTotal = nIn - nOut;
  30.  
  31. }
  32.  
  33. void loop() {
  34.  
  35. //Route AA
  36. label1
  37.  
  38. if (digitalRead(senAA1) == HIGH)
  39. {
  40. if (digitalRead(senAA2) == HIGH)
  41. {
  42. //add one axle to the In counter
  43. ++nIn;
  44. //do nothing whilst AA2 is still high
  45. while(digitalRead(senAA2) == HIGH);
  46. }
  47. else
  48. }
  49. ++nOut;
  50. {
  51. }
  52.  
  53. //Route AB
  54.  
  55. if (digitalRead(senAB1) == HIGH)
  56. {
  57. if (digitalRead(senAB2) == HIGH)
  58. {
  59. ++nIn;
  60. while(digitalRead(senAB2) == HIGH);
  61. }
  62. else
  63. }
  64. ++nOut;
  65. {
  66. }
  67.  
  68. //Route BB
  69.  
  70. if (digitalRead(senBB1) == HIGH)
  71. {
  72. if (digitalRead(senBB2) == HIGH)
  73. {
  74. ++nIn;
  75. while(digitalRead(senBB2) == HIGH);
  76. }
  77. else
  78. }
  79. ++nOut;
  80. {
  81. }
  82.  
  83. //Relay output HIGH if a train in section, LOW if not
  84.  
  85. if (ntotal == 0;)
  86. {
  87. digitalWrite(relOut1, HIGH);
  88. }
  89. else
  90. {
  91. digitalWrite(relOut1, LOW);
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement