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.
Motor.cpp@1:5dc94660e311, 2016-03-17 (annotated)
- Committer:
- Caconym
- Date:
- Thu Mar 17 14:53:03 2016 +0000
- Revision:
- 1:5dc94660e311
- Parent:
- 0:4318f664a8e1
yo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Caconym | 0:4318f664a8e1 | 1 | #include "Motor.h" |
Caconym | 0:4318f664a8e1 | 2 | |
Caconym | 0:4318f664a8e1 | 3 | Motor::Motor(PinName enablePin, PinName forwardPin, PinName backwardPin) |
Caconym | 1:5dc94660e311 | 4 | :motorEnable(enablePin),motorForward(forwardPin),motorBackward(backwardPin),motorSpeed(0) |
Caconym | 0:4318f664a8e1 | 5 | { |
Caconym | 1:5dc94660e311 | 6 | motorEnable.period(0.005f); |
Caconym | 0:4318f664a8e1 | 7 | } |
Caconym | 0:4318f664a8e1 | 8 | |
Caconym | 0:4318f664a8e1 | 9 | void Motor::SetDirection(MotDir direction) |
Caconym | 0:4318f664a8e1 | 10 | { |
Caconym | 0:4318f664a8e1 | 11 | switch(direction) |
Caconym | 0:4318f664a8e1 | 12 | { |
Caconym | 0:4318f664a8e1 | 13 | case NONE: |
Caconym | 0:4318f664a8e1 | 14 | motorForward = 0; |
Caconym | 0:4318f664a8e1 | 15 | motorBackward = 0; |
Caconym | 0:4318f664a8e1 | 16 | break; |
Caconym | 0:4318f664a8e1 | 17 | case FORWARD: |
Caconym | 0:4318f664a8e1 | 18 | motorForward = 1; |
Caconym | 0:4318f664a8e1 | 19 | motorBackward = 0; |
Caconym | 0:4318f664a8e1 | 20 | break; |
Caconym | 0:4318f664a8e1 | 21 | case BACKWARD: |
Caconym | 0:4318f664a8e1 | 22 | motorForward = 0; |
Caconym | 0:4318f664a8e1 | 23 | motorBackward = 1; |
Caconym | 0:4318f664a8e1 | 24 | break; |
Caconym | 0:4318f664a8e1 | 25 | } |
Caconym | 0:4318f664a8e1 | 26 | |
Caconym | 0:4318f664a8e1 | 27 | motorDirection = direction; |
Caconym | 0:4318f664a8e1 | 28 | } |
Caconym | 0:4318f664a8e1 | 29 | |
Caconym | 0:4318f664a8e1 | 30 | MotDir Motor::GetDirection() |
Caconym | 0:4318f664a8e1 | 31 | { |
Caconym | 0:4318f664a8e1 | 32 | return motorDirection; |
Caconym | 0:4318f664a8e1 | 33 | } |
Caconym | 0:4318f664a8e1 | 34 | |
Caconym | 0:4318f664a8e1 | 35 | void Motor::SetSpeed(float speed) |
Caconym | 0:4318f664a8e1 | 36 | { |
Caconym | 1:5dc94660e311 | 37 | motorEnable.write(speed); |
Caconym | 1:5dc94660e311 | 38 | motorSpeed = speed; |
Caconym | 0:4318f664a8e1 | 39 | } |
Caconym | 1:5dc94660e311 | 40 | |
Caconym | 1:5dc94660e311 | 41 | float Motor::GetSpeed() |
Caconym | 1:5dc94660e311 | 42 | { |
Caconym | 1:5dc94660e311 | 43 | return motorSpeed; |
Caconym | 1:5dc94660e311 | 44 | } |