narumi tatsuya
/
mou
ニョロゾ
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 _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 00027 if( speed > 0 ) 00028 { 00029 _pwm = ((float)speed) / 100.0; 00030 _fwd = 1; 00031 _rev = 0; 00032 } 00033 else if( speed < 0 ) 00034 { 00035 _pwm = -((float)speed) / 100.0; 00036 _fwd = 0; 00037 _rev = 1; 00038 } 00039 else 00040 { 00041 _fwd = 1; 00042 _rev = 1; 00043 } 00044 } 00045 00046 00047 // Speed Control with time-out 00048 // arg 00049 // int speed -100 -- 0 -- 100 00050 // int time 0 00051 void TB6612::move(int sspeed , int time) 00052 { 00053 speed(sspeed); 00054 wait_ms(time); 00055 } 00056 00057
Generated on Tue Jul 19 2022 23:08:50 by 1.7.2