Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. //assigning each pin a name to make it easier to 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 assining the initial values for total axles in and total axles out
  25. //also creating variable for 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.  
  37. if (digitalRead(senAA1) == HIGH)
  38. {
  39. if (digitalRead(senAA2) == HIGH)
  40. {
  41. ++nIn;
  42. while(digitalRead(senAA2) == HIGH);
  43. }
  44. else
  45. }
  46. ++nOut;
  47. {
  48. }
  49.  
  50. //Route AB
  51.  
  52. if (digitalRead(senAB1) == HIGH)
  53. {
  54. if (digitalRead(senAB2) == HIGH)
  55. {
  56. ++nIn;
  57. while(digitalRead(senAB2) == HIGH);
  58. }
  59. else
  60. }
  61. ++nOut;
  62. {
  63. }
  64.  
  65. //Route BB
  66.  
  67. if (digitalRead(senBB1) == HIGH)
  68. {
  69. if (digitalRead(senBB2) == HIGH)
  70. {
  71. ++nIn;
  72. while(digitalRead(senBB2) == HIGH);
  73. }
  74. else
  75. }
  76. ++nOut;
  77. {
  78. }
  79.  
  80. //Relay output HIGH if train in section, LOW if not
  81.  
  82. if (ntotal == 0;)
  83. {
  84. digitalWrite(relOut1, HIGH);
  85. }
  86. else
  87. {
  88. digitalWrite(relOut1, LOW);
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement