Jasmine Karlsson
/
train_rail
New project
Diff: Train.cpp
- Revision:
- 21:31647d80614f
- Parent:
- 20:32ba0a5f2d02
- Child:
- 23:bb57966cb776
--- a/Train.cpp Mon Jun 11 14:50:15 2018 +0000 +++ b/Train.cpp Tue Jun 12 15:02:44 2018 +0000 @@ -1,12 +1,13 @@ #include "Train.h" -Train::Train(const unsigned int newaddress, const unsigned int newinst) +Train::Train(const unsigned int newaddress, const unsigned int newinst, int pos) { //ctor address = newaddress; inst = newinst; - position = -1; - direction = true; + position = pos; + dirClockwise = false; + nrPacket = 20; } Train::~Train() @@ -19,14 +20,91 @@ return position; } -void Train::goForward(unsigned int forward){ +void Train::goForward(){ - inst = forward; DCC_send_command(address, inst, nrPacket); } -void Train::Stop(unsigned int stop){ - stop = 0x40; +void Train::changeSpeed(unsigned int speed){ + inst = speed; +} + +void Train::Stop(){ + unsigned int stop = 0x40; DCC_send_command(address, stop, nrPacket); +} + +unsigned int Train::getSpeed(){ + return inst; +} + +void Train::setPosition(int pos){ + position = pos; +} + +bool Train::checkInterupt(int pos){ + switch(pos){ + case 0: + if(position == 13 || position == 1) + return true; + break; + case 1: + if(position == 0 || position == 2) + return true; + break; + case 2: + if(position == 1 || position == 3 || position == 4) + return true; + break; + case 3: + if(position == 9 || position == 2) + return true; + break; + case 4: + if(position == 6 || position == 2) + return true; + break; + case 5: + if(position == 11 || position == 6) + return true; + break; + case 6: + if(position == 7 || position == 4 || position == 5) + return true; + break; + case 7: + if(position == 8 || position == 6) + return true; + break; + case 8: + if(position == 7 || position == 9 || position == 10) + return true; + break; + case 9: + if(position == 3 || position == 8) + return true; + break; + case 10: + if(position == 8 || position == 12) + return true; + break; + case 11: + if(position == 5 || position == 12) + return true; + break; + case 12: + if(position == 11 || position == 13 || position == 10) + return true; + break; + case 13: + if(position == 0 || position == 12) + return true; + break; + default: + lcd.cls(); + lcd.printf("Train not right one"); + break; + } + return false; } \ No newline at end of file