Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //assigning each pin a name to make it easier for both use in the program, and change the pin used in the future
- // using const unsigned char as this counts 0-255 and has a storage value of 1 byte, const so they are read-only
- const unsigned char senAA1 = 05
- const unsigned char senAA2 = 06
- const unsigned char senAB1 = 07
- const unsigned char senAB2 = 08
- const unsigned char senBB1 = 09
- const unsigned char senBB2 = 10
- const unsigned char relOut1 = 15
- void setup() {
- //declaring whether the pins used are input or output
- pinMode(senAA1, INPUT);
- pinMode(senAA2, INPUT);
- pinMode(senAB1, INPUT);
- pinMode(senAB2, INPUT);
- pinMode(senBB1, INPUT);
- pinMode(senBB2, INPUT);
- pinMode(relOut1, OUTPUT);
- //creating variables and assigning the initial values for total axles in and total axles out
- //also creating a variable for the total number of axles
- unsigned char nIn = 0;
- unsigned char nOut = 0;
- unsigned char nTotal = nIn - nOut;
- }
- void loop() {
- //Route AA
- label1
- if (digitalRead(senAA1) == HIGH)
- {
- if (digitalRead(senAA2) == HIGH)
- {
- //add one axle to the In counter
- ++nIn;
- //do nothing whilst AA2 is still high
- while(digitalRead(senAA2) == HIGH);
- }
- else
- }
- ++nOut;
- {
- }
- //Route AB
- if (digitalRead(senAB1) == HIGH)
- {
- if (digitalRead(senAB2) == HIGH)
- {
- ++nIn;
- while(digitalRead(senAB2) == HIGH);
- }
- else
- }
- ++nOut;
- {
- }
- //Route BB
- if (digitalRead(senBB1) == HIGH)
- {
- if (digitalRead(senBB2) == HIGH)
- {
- ++nIn;
- while(digitalRead(senBB2) == HIGH);
- }
- else
- }
- ++nOut;
- {
- }
- //Relay output HIGH if a train in section, LOW if not
- if (ntotal == 0;)
- {
- digitalWrite(relOut1, HIGH);
- }
- else
- {
- digitalWrite(relOut1, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement