You are viewing an older revision! See the latest version
Motor
An interface for driving a standard DC motor with PWM and an H-Bridge
Hello World!¶
main.cpp
// Sweep speed from full-speed reverse (-1.0) to forwards (1.0)
#include "mbed.h"
#include "Motor.h"
Motor m(p23, p6, p5); // pwm, fwd, rev
int main() {
for (float s= -1.0; s < 1.0 ; s += 0.01) {
m.speed(s);
wait(0.02);
}
}
Library¶
Example¶
This example show you how to wire up the L293D dual H bridge driver. Data sheet can be found at:

some minor additions to the libary above, resulted in this libary. It has been tested on L298 motor drivers, but uses the same method of speed control.
in terms of use, the speed control is exactly the same. the coast function means the motor driver switches off, and does nothing.
the stop function dynamicaly brakes, which is supported on L298's but if dynamic braking develops more current than the motor drivers are rated for, things start to fail. read data sheet, and if in doubt, don't.
main.cpp
00071 // test code, this demonstrates working motor drivers.
00072 // full reverse to full stop, dynamicaly brake and switch off.
#include motordriver.h
00073 Motor A(p22, p6, p5, 1); // pwm, fwd, rev, can brake
00074 Motor B(p21, p7, p8, 1); // pwm, fwd, rev, can brake
00075 int main() {
00076 for (float s= -1.0; s < 1.0 ; s += 0.01) {
00077 A.speed(s);
00078 B.speed(s);
00079 wait(0.02);
00080 }
00081 A.stop();
00082 B.stop();
00083 wait(1);
00084 A.coast();
00085 B.coast();
00086 }
data sheet for L298
conection diagrams to follow when Ive worked out how to upload them, poking paper at the ethernet port didn't work. it connects to a L293 in the same way.