relayMD
Fork of Motor by
Revision 1:0efe3050d83e, committed 2016-09-29
- Comitter:
- number_key
- Date:
- Thu Sep 29 16:49:58 2016 +0000
- Parent:
- 0:ebfdfce2d069
- Commit message:
- relayMD
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 ebfdfce2d069 -r 0efe3050d83e motor.cpp --- a/motor.cpp Mon Sep 05 00:49:28 2016 +0000 +++ b/motor.cpp Thu Sep 29 16:49:58 2016 +0000 @@ -8,19 +8,10 @@ _pin3 = 0; } -void Motor::motor(float n) +void Motor::motor(double n) { - if(n > 0) { - _pin1=0; - _pin2=1; - _pin3=n; - } else if(n < 0) { - _pin1=1; - _pin2=0; - _pin3=-n; - } else { - _pin1=0; - _pin2=0; - _pin3=1; - } + _pin1 = (n<0); + _pin2 = (n>0); + if(n) _pin3 = 1.0; + else _pin3 = fabs(n); } \ No newline at end of file
diff -r ebfdfce2d069 -r 0efe3050d83e motor.h --- a/motor.h Mon Sep 05 00:49:28 2016 +0000 +++ b/motor.h Thu Sep 29 16:49:58 2016 +0000 @@ -7,7 +7,7 @@ public: //pin1,pin2 Digital pin3 Pwm Motor(PinName pin1, PinName pin2, PinName pin3); - void motor(float n); + void motor(double n); private: DigitalOut _pin1;