a

TB6612.cpp

Committer:
miyajitakenari
Date:
2021-11-06
Revision:
5:096c2484805d
Parent:
4:95d5e9ee8c15

File content as of revision 5:096c2484805d:

#include "TB6612.h"

// TB6612 Class Constructor
TB6612::TB6612(PinName pwm, PinName fwd, PinName rev):
        _pwm(pwm), _fwd(fwd), _rev(rev) {

    _fwd = 0;
    _rev = 0;
    _pwm = 0.0;
    stat = 0;
    _pwm.period(0.001);
    
}

// Speed Control
//  arg
//   float speed -1.0 - 0.0 - 1.0
float TB6612::speed(double speed) {
    
    if( speed > 0.0 )
    {
        _pwm = speed;
        _fwd = 1;
        _rev = 0;
        stat = 1;
    }
    else if( speed < 0.0 )
    {
        _pwm = -speed;
        _fwd = 0;
        _rev = 1;
        stat = -1;
    }
    else
    {
        _fwd = 1;
        _rev = 1;
        stat = 0;
    }
    return speed==0 ? 0 : speed > 0 ? 1 : -1;
}