Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Motor.cpp
- Revision:
- 0:0f53faf3b186
- Child:
- 1:727b2172d97c
diff -r 000000000000 -r 0f53faf3b186 Motor.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.cpp Tue Jan 19 11:29:43 2016 +0000
@@ -0,0 +1,30 @@
+#include "Motor.h"
+
+#include "mbed.h"
+
+motor::motor(PinName PWM, PinName fwd, PinName rev ,float period ,int select):
+ pwm(PWM), cw(fwd), ccw(rev)
+{
+ pwm.period(period);
+ if(select>1) {
+ mode = 1;
+ pwm = 0.5;
+ } else {
+ mode = 0;
+ pwm = 0;
+ cw = 0;
+ ccw = 0;
+ }
+
+}
+void motor::speed(float speed)
+{
+ if(mode == 0) {
+ cw = (speed > 0.0);
+ ccw = (speed < 0.0);
+ pwm = abs(speed);
+ } else if(mode > 0) {
+ pwm = 0.5+(speed*0.5);
+ }
+}
+