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:
- 3:c3d716d6c6a7
- Parent:
- 2:2cc70773996b
- Child:
- 4:95fe80130442
--- a/main.cpp Thu Mar 26 06:10:56 2015 +0000 +++ b/main.cpp Thu Mar 26 23:41:44 2015 +0000 @@ -8,15 +8,25 @@ DigitalOut myled(LED1); +void moveForward (){ + dcMotor.forward(); + movingDirection = 1; +} + +void moveReverse(){ + dcMotor.reverse(); + movingDirection = -1; +} + void floorChosen (int i){ queue.add(i); if(!dcMotor.isMoving()){ - if(i == currentFloor){ + if(i == currentFloor){ floorReached(i); }else if(i>currentFloor){ - dcMotor.forward(); + moveForward(); }else{ - dcMotor.reverse(); + moveReverse(); } } } @@ -33,7 +43,23 @@ void floorReached (int i){ doStopOperation(); queue.remove(i); - //choose next floor + if(movingDirection == 1){ + if(queue.isForwardRequested(i)){ + moveForward(); + }else if(queue.isReverseRequested(i)){ + moveReverse(); + }else{ + movingDirection = 0; + } + }else{ + if(queue.isReverseRequested(i)){ + moveReverse(); + }else if(queue.isForwardRequested(i)){ + moveForward(); + }else{ + movingDirection = 0; + } + } } void floorDetected (int i){