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.
L298LIB.cpp
00001 #include "L298LIB.h" 00002 L298LIB::L298LIB(PinName pinEnable, PinName pinIN1, PinName pinIN2, PinName pinIN3, PinName pinIN4): 00003 _pwm(pinEnable), 00004 _pinIN1 (pinIN1), 00005 _pinIN2 (pinIN2), 00006 _pinIN3 (pinIN3), 00007 _pinIN4 (pinIN4) 00008 { 00009 _pwm.period_us(25); // 40kHz 00010 _pwm = 0.; 00011 _pinIN1 = 0; 00012 _pinIN2 = 0; 00013 _pinIN3 = 0; 00014 _pinIN4 = 0; 00015 } 00016 void L298LIB::setSpeed(float pwmVal) 00017 { 00018 _pwm = pwmVal; 00019 } 00020 float L298LIB::getSpeed() 00021 { 00022 return _pwm; 00023 } 00024 void L298LIB::forward() 00025 { 00026 _pinIN1=1; 00027 _pinIN2=0; 00028 _pinIN3=1; 00029 _pinIN4=0; 00030 } 00031 void L298LIB::backward() 00032 { 00033 _pinIN1=0; 00034 _pinIN2=1; 00035 _pinIN3=0; 00036 _pinIN4=1; 00037 } 00038 void L298LIB::stop() 00039 { 00040 _pinIN1=0; 00041 _pinIN2=0; 00042 _pinIN3=0; 00043 _pinIN4=0; 00044 } 00045 void L298LIB::run(float vel) 00046 { 00047 if (vel>=0) { 00048 setSpeed((vel>1.0f) ? 1.0f:vel); 00049 forward(); 00050 } else { 00051 setSpeed((vel<-1.0f) ? 1.0f:-vel); 00052 backward(); 00053 } 00054 }
Generated on Thu Jul 14 2022 09:41:36 by
1.7.2