Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
TB6612.cpp
00001 /** 00002 * Motor Driver TB6612 Control Library 00003 * 00004 * -- TB6612 is a device of the TOSHIBA. 00005 * 00006 * Copyright (C) 2012 Junichi Katsu (JKSOFT) 00007 */ 00008 00009 00010 #include "TB6612.h" 00011 00012 // TB6612 Class Constructor 00013 TB6612::TB6612(PinName pwm, PinName fwd, PinName rev): 00014 _pwm(pwm), _fwd(fwd), _rev(rev) { 00015 00016 _fwd = 0; 00017 _rev = 0; 00018 _pwm = 0.0; 00019 _pwm.period(0.001); 00020 00021 bspeed = 0.0; 00022 timer_flag = false; 00023 } 00024 00025 // Speed Control 00026 // arg 00027 // float speed -1.0 - 0.0 - 1.0 00028 void TB6612::speed(float speed) { 00029 00030 if( timer_flag == true ) return; 00031 00032 bspeed = speed; 00033 00034 if( speed > 0.0 ) 00035 { 00036 _pwm = speed; 00037 _fwd = 1; 00038 _rev = 0; 00039 } 00040 else if( speed < 0.0 ) 00041 { 00042 _pwm = -speed; 00043 _fwd = 0; 00044 _rev = 1; 00045 } 00046 else 00047 { 00048 _fwd = 1; 00049 _rev = 1; 00050 } 00051 } 00052 00053 00054 // Speed Control with time-out 00055 // arg 00056 // float sspeed:-1.0 - 0.0 - 1.0 00057 // float time :0.0- 00058 void TB6612::move(float sspeed , float time) 00059 { 00060 speed(sspeed); 00061 timer_flag = true; 00062 timer.attach(this,&TB6612::timeout,time); 00063 } 00064 00065 00066 void TB6612::timeout() 00067 { 00068 timer_flag = false; 00069 speed(bspeed); 00070 } 00071
Generated on Tue Jul 12 2022 20:04:43 by
