zhouhang shao
/
test
test
Diff: motor.cpp
- Revision:
- 6:9f698d1b2996
- Parent:
- 2:b78dfa2afe92
--- a/motor.cpp Tue May 09 01:21:47 2017 +0000 +++ b/motor.cpp Sat May 13 19:42:23 2017 +0000 @@ -1,31 +1,28 @@ +/* #include "motor.h" -const int FORWARD = 1; -const int BACKWARD = 0; +#include "mbed.h" const int ONE_MILLISECOND = 0.001; -Motor::Motor(PinName _pwm_pin, PinName _dir): +Motor::Motor(PinName curr_pwm_pin, PinName curr_dir): pwm_pin(_pwm_pin), dir(_dir){ + pwm_pin(curr_pwm_pin); + dir(curr_dir); + pwm_pin.period(ONE_MILLISECOND); - pwm_pin = 0; + pwm_pin.write(0.1f); dir = 0; curr_speed = 0; } //Sets motor speed void Motor::speed(float speed) { - if (speed < 0.0f){ //Backwards - if (speed < -1.0f){ - speed = -1.0f; - } - dir = FORWARD; - pwm_pin = curr_speed = speed + 1.0f; // Inverts it so 1 is off and 0 is on - } else { //Forwards - dir = BACKWARD; - pwm_pin = curr_speed = speed; - } + curr_speed = speed; + pwm_pin.write(speed); } //Sets motor speed to 0 void Motor::stop() { speed(0); -} \ No newline at end of file +} + +*/ \ No newline at end of file