Init
Dependents: JetflyerMotorController
Diff: Motor.cpp
- Revision:
- 1:39b173360768
- Parent:
- 0:5eb2bad9ea40
--- a/Motor.cpp Mon Jun 12 19:58:20 2017 +0000 +++ b/Motor.cpp Thu Jul 13 13:42:32 2017 +0000 @@ -0,0 +1,44 @@ +#include "Motor.h" + + +Motor::Motor() : forward(pin_forward),backward(pin_backward),throttle(pin_pwm_motor) +{ + +direction_old = 1; +} + +Motor::~Motor() +{ + +} + +//speed in percent + int Motor::drive(int speed, int direction) + { + // if direction change is detected both pins are set to 0 + if(direction_old != direction) + { + backward =0; + forward = 0; + } + else + { + + if(direction == 1) + { + backward =0; + forward =1; + } + if(direction == -1) + { + backward =1; + forward =0; + + } + + } + + throttle.write(((float)speed)/100.0f); + direction_old = direction; + return 0; + } \ No newline at end of file