Simple PWM for motor control

Dependencies:   mbed

This program is for motor control with Arduino motor shield and LCP 1768.

For motor control with arduino motor shield, it needs direction signal and brake signal. Maybe brake signal is optional. So, the code use three pins, direction(gpio), brake(gpio) and PWM output.

- Schematic /media/uploads/hjjeon/lpc1768_motor_shield_schem.jpg

main.cpp

Committer:
hjjeon
Date:
2014-11-18
Revision:
0:5f85a7752a04
Child:
1:4f47e58cd882

File content as of revision 0:5f85a7752a04:

#include "mbed.h"

#define FORWARD     0
#define BACKWARD    1

DigitalOut myled(LED1);

int main() {
        
    Serial pc(USBTX, USBRX);
    pc.baud(115200);
    
    PwmOut mypwm(p21);
    DigitalOut direction(p5);
    DigitalOut brake(p6);
    
    direction = FORWARD;// FORWARD == 0;.
    
    while(1) {
        myled = !myled;
        mypwm = mypwm + 0.05;
        wait(3);
        if( mypwm >= 1)
        {
            brake = 1; //stop
        }
    }
}