Simple Interface for Toshiba's TB6612FNG H-Bridge Motor Driver

TB6612FNG.h

Committer:
humlet
Date:
2013-03-04
Revision:
0:30d6828516f5
Child:
1:3dd9137a5cec

File content as of revision 0:30d6828516f5:

/**
 * H-Bridge / Motor Driver TB6612FNG Control Library
 */

#ifndef TB6612FNG_H
#define TB6612FNG_H

#include "mbed.h"

class TB6612FNG
{
    PwmOut m_pwm;
    DigitalOut m_ctrl1;
    DigitalOut m_ctrl2;
    int m_dc;
    bool m_on;

public:
    /** Create TB6612FNG object connected to the specified mbed pins
    * @param pwm PwmOut pin
    * @param ctrl1/ctrl2 DigitalOut control pin
    */
    TB6612FNG(PinName pwm, PinName ctrl1, PinName ctrl2);
    /// Set the duty cycle
    /// @param dc in permille [-1000,1000]
    void setDC(int dc);
    /// activate the motor at given duty cycle
    void on();
    /// deactivate the motor
    void off();
    /// break the motor by shorting it 
    void brake();
    /// duty cycle assignment
    /// @param dc in permille [-1000,1000]
    void operator=(int dc) {
        setDC(dc);
    }
};

#endif