Jasmine Karlsson
/
train_rail
New project
Train.cpp
- Committer:
- jasminealice
- Date:
- 2018-06-13
- Revision:
- 23:bb57966cb776
- Parent:
- 21:31647d80614f
- Child:
- 24:418711ed8c52
File content as of revision 23:bb57966cb776:
#include "Train.h" Train::Train(const unsigned int newaddress, const unsigned int newinst, int pos) { //ctor address = newaddress; inst = newinst; position = pos; dirClockwise = false; nrPacket = 20; } Train::~Train() { //dtor } int Train::getPosition(){ return position; } void Train::sendCommand(){ //lcd.cls(); //lcd.printf("Send command"); //lcd.printf("%d", inst); DCC_send_command(address, inst, nrPacket); } void Train::changeSpeed(unsigned int speed){ inst = speed; } void Train::Stop(){ inst = 0x40; DCC_send_command(address, inst, nrPacket); } unsigned int Train::getSpeed(){ return inst; } void Train::setPosition(int pos){ position = pos; } bool Train::isClockwise(){ return dirClockwise; } void Train::changeDirection(){ dirClockwise = !dirClockwise; } 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; }