Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 37:bb15bea420a3
- Parent:
- 35:cfcfeccb959e
- Child:
- 39:9cce8f2c50b6
--- a/main.cpp Thu Jun 14 10:14:59 2018 +0000 +++ b/main.cpp Thu Jun 14 10:32:54 2018 +0000 @@ -179,6 +179,7 @@ vector<Position> positions; + //Starting position and orientation of the trains int DR_train_pos = D4; bool DR_cw = true; @@ -295,12 +296,13 @@ /** * -*/ - +*Returns the number of the sensor where the train was detected. +* +**/ int get_sensor(unsigned int number,int interrupt){ int sensor = -1; - for(int i=0; i<8;i++){ + for(int i=0; i<8; i++){ if(~number & 1<<i){ sensor = i; @@ -308,7 +310,7 @@ } if(interrupt == 1){ - sensor+=8; // Sensors caught by interreupt1 are identified from 8 to 15. + sensor+= 8; // Sensors caught by interreupt1 are identified from 8 to 15. } return sensor; } @@ -317,13 +319,15 @@ bool found_DR = false; bool found_LR = false; - Position pos = positions[sensor]; - for(int i = 0; i<pos.get_prev_cw().size();i++){ + Position pos = positions[sensor]; + for(int i = 0; i<pos.get_prev_cw().size();i++){ int prev = pos.get_prev_cw()[i]; + if(DR_train_pos == prev){ found_DR = true; DR_train_pos = prev; //We update the position of the train } + if(LR_train_pos == prev){ found_LR = true; LR_train_pos = prev; //We update the position of the train @@ -335,7 +339,7 @@ lcd.printf("DR is at D%d",DR_train_pos); } if(found_LR){ - lcd.cls(); + lcd.cls(); lcd.printf("LR is at D%d",LR_train_pos); } if(!found_DR && !found_LR){ @@ -344,6 +348,7 @@ } } + /** * *Method to catch interrupts 0 @@ -389,34 +394,6 @@ } - - -/** -* -*Print the positions where there is a 0 -* -**/ - -void train_pos_update(unsigned int number){ - - /* - bitset <sizeof(unsigned int) * 8> n (number); - - cout << "Binary: " << n << endl; - */ - - for(int i=0; i<16;i++){ - - if(~number & 1<<i){ - - cout << "There is a 0 at " << i << endl; - pos_trains[1] = pos_trains[0]; - pos_trains[0] = i; - } - } - } - - /** * *Method to send DCC commands to train and switches.