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.
Revision 0:5307ae36f268, committed 2014-06-14
- Comitter:
- mariob
- Date:
- Sat Jun 14 21:56:12 2014 +0000
- Commit message:
- example to test motion boards
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dc_motor.cpp Sat Jun 14 21:56:12 2014 +0000
@@ -0,0 +1,14 @@
+#include "dc_motor.hpp"
+
+DC_motor::DC_motor (PinName ppwm, PinName pdir): pwm(ppwm), dir(pdir)
+{
+ pwm.period(0.001);
+ pwm = 0;
+ dir = 0;
+}
+
+void DC_motor::speed (float speed)
+{
+ dir = speed>0.0;
+ pwm = abs(speed);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dc_motor.hpp Sat Jun 14 21:56:12 2014 +0000
@@ -0,0 +1,19 @@
+#ifndef DC_MOTOR
+#define DC_MOTOR
+
+#include "mbed.h"
+
+class DC_motor
+{
+ PwmOut pwm;
+ DigitalOut dir;
+
+public:
+
+ DC_motor (PinName ppwm, PinName pdir);
+
+ void speed(float speed);
+
+};
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sat Jun 14 21:56:12 2014 +0000
@@ -0,0 +1,26 @@
+#include "mbed.h"
+#include "dc_motor.hpp"
+
+int main ()
+{
+ AnalogIn vert(p20);
+ AnalogIn horz(p19);
+ DC_motor m_sx(p21, p22);
+ DC_motor m_dx(p23, p24);
+
+ while(1) {
+ wait(0.2);
+ float v = vert.read();
+ float h = horz.read();
+ float speed_sx = (v-0.5)*2.0;
+ if (h>0.5)
+ speed_sx *= (1.0-(h-0.5)*2.0);
+ float speed_dx = (v-0.5)*2.0;
+ if (h<0.5)
+ speed_dx *= ((h+0.5)*2.0-1.0);
+ m_sx.speed(speed_sx);
+ m_dx.speed(speed_dx);
+// printf("VERT(%f), HORZ(%f), sx(%f), dx(%f)\n\r",
+// vert.read(), horz.read(), speed_sx, speed_dx);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Jun 14 21:56:12 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/024bf7f99721 \ No newline at end of file