PRAWIRA
Motor.cpp@0:86d90c65f83b, 2019-09-16 (annotated)
- Committer:
- alienbernamaihsan
- Date:
- Mon Sep 16 10:06:48 2019 +0000
- Revision:
- 0:86d90c65f83b
PRAWIRA; ;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alienbernamaihsan | 0:86d90c65f83b | 1 | #include "Motor.h" |
alienbernamaihsan | 0:86d90c65f83b | 2 | |
alienbernamaihsan | 0:86d90c65f83b | 3 | Motor::Motor(PinName dright, PinName dleft, PinName pwmpin): dright_(dright), dleft_(dleft), pwmpin_(pwmpin) { |
alienbernamaihsan | 0:86d90c65f83b | 4 | pwmpin_.period_us(50); |
alienbernamaihsan | 0:86d90c65f83b | 5 | } |
alienbernamaihsan | 0:86d90c65f83b | 6 | |
alienbernamaihsan | 0:86d90c65f83b | 7 | void Motor::setpwm(float inputpwm) { |
alienbernamaihsan | 0:86d90c65f83b | 8 | if (inputpwm >= 0) { |
alienbernamaihsan | 0:86d90c65f83b | 9 | dright_ = 1; |
alienbernamaihsan | 0:86d90c65f83b | 10 | dleft_ = 0; |
alienbernamaihsan | 0:86d90c65f83b | 11 | pwmpin_.write(inputpwm); |
alienbernamaihsan | 0:86d90c65f83b | 12 | } else { |
alienbernamaihsan | 0:86d90c65f83b | 13 | dright_ = 0; |
alienbernamaihsan | 0:86d90c65f83b | 14 | dleft_ = 1; |
alienbernamaihsan | 0:86d90c65f83b | 15 | pwmpin_.write(-1 * inputpwm); |
alienbernamaihsan | 0:86d90c65f83b | 16 | } |
alienbernamaihsan | 0:86d90c65f83b | 17 | } |