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.
L298.cpp
00001 #include "L298_H.h" 00002 #include <mbed.h> 00003 00004 00005 L298::L298(PinName pin1, PinName pin2, PinName pin3):m_motorEnable(pin1),m_motorBw(pin2),m_motorFw(pin3){ 00006 /*class constructor : initializes the motors with 00007 forward enable and speed of 0.3 */ 00008 00009 //m_dir = true; 00010 //m_speed = 0.2; 00011 00012 m_motorEnable.period_ms(10); 00013 00014 SetDirection(1); 00015 SetSpeed(0.0); 00016 } 00017 00018 00019 void L298::SetDirection(bool dir){ 00020 /*set direction of one of the sides depending on pwmSelect 00021 direction : 1 go forward ,0 go backwards*/ 00022 00023 00024 00025 if(dir){ 00026 m_motorBw = 0; 00027 m_motorFw = 1; 00028 } 00029 else{ 00030 m_motorBw = 1; 00031 m_motorFw = 0; 00032 } 00033 00034 00035 m_prevDir = dir; 00036 00037 } 00038 00039 00040 void L298::SetSpeed(float speed){ 00041 /*set speed on the pwm which is point by m_pwmPtr (set by SetDirection) 00042 speed : the speed given to the motor, ranges from 0 to 1*/ 00043 00044 if(speed<=0) m_motorEnable.write(0); 00045 else if(speed>=1.0)m_motorEnable.write(1.0); 00046 else m_motorEnable.write(speed); 00047 00048 } 00049 00050 void L298::Stop(){ 00051 m_motorEnable.write(0); 00052 } 00053 00054
Generated on Sat Aug 6 2022 16:18:59 by
1.7.2