program for encoder
Revision 4:79e803bc20ca, committed 2021-06-16
- Comitter:
- noamnahum
- Date:
- Wed Jun 16 18:44:41 2021 +0000
- Parent:
- 3:42a75eba182b
- Commit message:
- for itay
Changed in this revision
Motor.cpp | Show annotated file Show diff for this revision Revisions of this file |
Motor.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 42a75eba182b -r 79e803bc20ca Motor.cpp --- a/Motor.cpp Tue Jan 07 08:57:50 2020 +0000 +++ b/Motor.cpp Wed Jun 16 18:44:41 2021 +0000 @@ -24,21 +24,24 @@ #include "mbed.h" -Motor::Motor(PinName pwm, PinName fwd, PinName rev): - _pwm(pwm), _fwd(fwd), _rev(rev) { +Motor::Motor(PinName pwm, PinName fwd): + _pwm(pwm), _fwd(fwd) { // Set initial condition of PWM - _pwm.period(0.00005); + _pwm.period(0.005); _pwm = 0; // Initial condition of output enables _fwd = 0; - _rev = 0; } void Motor::speed(float speed) { - _fwd = (speed > 0.0); - _rev = (speed < 0.0); + if(speed > 0){ + _fwd = true; + } + else{ + _fwd = false; + } _pwm = abs(speed); }
diff -r 42a75eba182b -r 79e803bc20ca Motor.h --- a/Motor.h Tue Jan 07 08:57:50 2020 +0000 +++ b/Motor.h Wed Jun 16 18:44:41 2021 +0000 @@ -38,18 +38,18 @@ * @param fwd A DigitalOut, set high when the motor should go forward * @param rev A DigitalOut, set high when the motor should go backwards */ - Motor(PinName pwm, PinName fwd, PinName rev); + Motor(PinName pwm, PinName fwd); /** Set the speed of the motor * * @param speed The speed of the motor as a normalised value between -1.0 and 1.0 */ void speed(float speed); + void speed1(float speed1); protected: PwmOut _pwm; DigitalOut _fwd; - DigitalOut _rev; };