Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
vcazan
Date:
Sun Jan 17 17:17:06 2010 +0000
Commit message:

Changed in this revision

Main.cpp Show annotated file Show diff for this revision Revisions of this file
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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 552b174f8c2f Main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Main.cpp	Sun Jan 17 17:17:06 2010 +0000
@@ -0,0 +1,41 @@
+#include "mbed.h"
+#include "Motor.h"
+
+Motor m(p23, p16, p17);
+Motor m2(p24, p18, p19);
+DigitalOut myled(LED1);
+DigitalOut myled2(LED2);
+
+
+int main() {
+
+    // wind up to full speed
+    for (float speed=0.0; speed < 1.0 ; speed += 0.01) {
+       m.speed(speed); 
+       m2.speed(speed-0.6);
+       wait(0.02);
+       myled = 0;
+       myled2 = 1;
+    }
+
+
+    while(1) {
+        myled = 1;
+        myled2 = 0;
+        // Go from full speed forward, to full speed reverse
+        for (float speed=0.6; speed > -1.0 ; speed -= 0.1) {
+        m.speed(speed); 
+        m2.speed(speed);
+        myled = 0;
+       myled2 = 1;
+        wait(0.02);}
+
+        // Go from full speed reverse, to full speed forward
+        for (float speed=-0.6; speed < 1.0 ; speed += 0.1) {
+        m.speed(speed); 
+        m2.speed(speed);
+        myled = 1;
+       myled2 = 0;
+        wait(0.02);}
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 552b174f8c2f Motor.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.cpp	Sun Jan 17 17:17:06 2010 +0000
@@ -0,0 +1,32 @@
+#include "Motor.h"
+#include "mbed.h"
+
+
+/* 
+ * Constructor
+ */
+Motor::Motor(PinName pwm, PinName fwd, PinName rev): 
+    _pwm(pwm), _fwd(fwd), _rev(rev) {    
+    
+    // Set initial condition of PWM
+    _pwm.period(0.001);
+    _pwm = 0;
+
+    // Initial condition of output enables
+    _fwd = 0;
+    _rev = 0;
+
+}
+
+    
+/* 
+ * Set the speed
+ */
+void Motor::speed(float speed) {
+        _fwd = (speed > 0.0);
+        _rev = (speed < 0.0);
+        _pwm = abs(speed);
+}
+
+
+
diff -r 000000000000 -r 552b174f8c2f Motor.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.h	Sun Jan 17 17:17:06 2010 +0000
@@ -0,0 +1,20 @@
+#ifndef MBED_MOTOR_H
+#define MBED_MOTOR_H
+
+#include "mbed.h"
+
+class Motor {
+
+    public:
+
+        Motor(PinName pwm, PinName fwd, PinName rev);
+        void speed (float);
+        
+    protected: 
+        PwmOut _pwm;
+        DigitalOut _fwd;
+        DigitalOut _rev;
+
+};
+
+#endif
diff -r 000000000000 -r 552b174f8c2f mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Jan 17 17:17:06 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/20a79241b4a0