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.
Diff: L298LIB.cpp
- Revision:
- 0:dd3d9657fd9f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/L298LIB.cpp Sat Jun 04 05:41:18 2022 +0000
@@ -0,0 +1,54 @@
+#include "L298LIB.h"
+L298LIB::L298LIB(PinName pinEnable, PinName pinIN1, PinName pinIN2, PinName pinIN3, PinName pinIN4):
+ _pwm(pinEnable),
+ _pinIN1 (pinIN1),
+ _pinIN2 (pinIN2),
+ _pinIN3 (pinIN3),
+ _pinIN4 (pinIN4)
+{
+ _pwm.period_us(25); // 40kHz
+ _pwm = 0.;
+ _pinIN1 = 0;
+ _pinIN2 = 0;
+ _pinIN3 = 0;
+ _pinIN4 = 0;
+}
+void L298LIB::setSpeed(float pwmVal)
+{
+ _pwm = pwmVal;
+}
+float L298LIB::getSpeed()
+{
+ return _pwm;
+}
+void L298LIB::forward()
+{
+ _pinIN1=1;
+ _pinIN2=0;
+ _pinIN3=1;
+ _pinIN4=0;
+}
+void L298LIB::backward()
+{
+ _pinIN1=0;
+ _pinIN2=1;
+ _pinIN3=0;
+ _pinIN4=1;
+}
+void L298LIB::stop()
+{
+ _pinIN1=0;
+ _pinIN2=0;
+ _pinIN3=0;
+ _pinIN4=0;
+}
+void L298LIB::run(float vel)
+{
+ if (vel>=0) {
+ setSpeed((vel>1.0f) ? 1.0f:vel);
+ forward();
+ } else {
+ setSpeed((vel<-1.0f) ? 1.0f:-vel);
+ backward();
+ }
+}
\ No newline at end of file