under constructiong
Fork of BLE_WallbotBLE_Challenge by
Embed:
(wiki syntax)
Show/hide line numbers
TB6612.cpp
00001 /* wallbot mini Library 00002 * 00003 * wallbotmini.cpp 00004 * 00005 * Copyright (c) 2010-2013 jksoft 00006 * 00007 * Permission is hereby granted, free of charge, to any person obtaining a copy 00008 * of this software and associated documentation files (the "Software"), to deal 00009 * in the Software without restriction, including without limitation the rights 00010 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00011 * copies of the Software, and to permit persons to whom the Software is 00012 * furnished to do so, subject to the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included in 00015 * all copies or substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00018 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00020 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00021 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00022 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00023 * THE SOFTWARE. 00024 */ 00025 00026 00027 #include "TB6612.h" 00028 00029 // TB6612 Class Constructor 00030 TB6612::TB6612(PinName pwm, PinName fwd, PinName rev): 00031 _pwm(pwm), _fwd(fwd), _rev(rev) { 00032 00033 _fwd = 0; 00034 _rev = 0; 00035 _pwm = 0.0; 00036 stat = 0; 00037 _pwm.period(0.001); 00038 00039 } 00040 00041 // Speed Control 00042 // arg 00043 // float speed -1.0 - 0.0 - 1.0 00044 float TB6612::speed(float speed) { 00045 00046 00047 00048 if( speed > 0.0 ) 00049 { 00050 //if( speed > 0.7) speed = 1.0; 00051 _pwm = speed; 00052 _fwd = 1; 00053 _rev = 0; 00054 stat = 1; 00055 } 00056 else if( speed < 0.0 ) 00057 { 00058 //if( speed < -0.7) speed = -1.0; 00059 _pwm = -speed; 00060 _fwd = 0; 00061 _rev = 1; 00062 stat = -1; 00063 } 00064 else 00065 { 00066 _fwd = 1; 00067 _rev = 1; 00068 stat = 0; 00069 } 00070 return speed==0 ? 0 : speed > 0 ? 1 : -1; 00071 }
Generated on Tue Jul 12 2022 20:46:10 by
1.7.2
