Initial Fork
Embed:
(wiki syntax)
Show/hide line numbers
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 scale(1), _pwm(pwm), _fwd(fwd), _rev(rev) { 00015 00016 _fwd = 0; 00017 _rev = 0; 00018 _pwm = 0.0; 00019 _pwm.period(0.001); 00020 } 00021 00022 // Speed Control 00023 // arg 00024 // int speed -100 -- 0 -- 100 00025 void TB6612::speed(int speed_) { 00026 _speed = speed_; 00027 float speed = scale*(float)speed_; 00028 00029 if( speed > 0 ) 00030 { 00031 _pwm = ((float)speed)/ 100.0; 00032 _fwd = 1; 00033 _rev = 0; 00034 } 00035 else if( speed < 0 ) 00036 { 00037 _pwm = -((float)speed)/ 100.0; 00038 _fwd = 0; 00039 _rev = 1; 00040 } 00041 else 00042 { 00043 _fwd = 1; 00044 _rev = 1; 00045 } 00046 } 00047 int TB6612::getSpeed(){ 00048 return _speed; 00049 } 00050
Generated on Mon Jul 18 2022 15:02:32 by 1.7.2