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.
LineFollowingRobot/L298.cpp@7:b9c2097e5cb2, 2019-03-14 (annotated)
- Committer:
- Nicolaemf
- Date:
- Thu Mar 14 12:31:39 2019 +0000
- Revision:
- 7:b9c2097e5cb2
- Parent:
- 6:b457f1e2fff8
correction of minor build bugs;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nicolaemf | 6:b457f1e2fff8 | 1 | #include "L298_H.h" |
Nicolaemf | 6:b457f1e2fff8 | 2 | #include <mbed.h> |
Nicolaemf | 6:b457f1e2fff8 | 3 | |
Nicolaemf | 6:b457f1e2fff8 | 4 | |
Nicolaemf | 6:b457f1e2fff8 | 5 | L298::L298(PinName pin1, PinName pin2, PinName pin3):m_motorEnable(pin1),m_motorBw(pin2),m_motorFw(pin3){ |
Nicolaemf | 6:b457f1e2fff8 | 6 | /*class constructor : initializes the motors with |
Nicolaemf | 6:b457f1e2fff8 | 7 | forward enable and speed of 0.3 */ |
Nicolaemf | 6:b457f1e2fff8 | 8 | |
Nicolaemf | 6:b457f1e2fff8 | 9 | //m_dir = true; |
Nicolaemf | 6:b457f1e2fff8 | 10 | //m_speed = 0.2; |
Nicolaemf | 6:b457f1e2fff8 | 11 | |
Nicolaemf | 6:b457f1e2fff8 | 12 | m_motorEnable.period_ms(1); |
Nicolaemf | 6:b457f1e2fff8 | 13 | |
Nicolaemf | 6:b457f1e2fff8 | 14 | SetDirection(1); |
Nicolaemf | 6:b457f1e2fff8 | 15 | SetSpeed(0.2); |
Nicolaemf | 6:b457f1e2fff8 | 16 | } |
Nicolaemf | 6:b457f1e2fff8 | 17 | |
Nicolaemf | 6:b457f1e2fff8 | 18 | |
Nicolaemf | 7:b9c2097e5cb2 | 19 | void L298::SetDirection(bool dir){ |
Nicolaemf | 6:b457f1e2fff8 | 20 | /*set direction of one of the sides depending on pwmSelect |
Nicolaemf | 6:b457f1e2fff8 | 21 | direction : 1 go forward ,0 go backwards*/ |
Nicolaemf | 6:b457f1e2fff8 | 22 | |
Nicolaemf | 6:b457f1e2fff8 | 23 | |
Nicolaemf | 6:b457f1e2fff8 | 24 | |
Nicolaemf | 6:b457f1e2fff8 | 25 | if(dir){ |
Nicolaemf | 6:b457f1e2fff8 | 26 | m_motorBw = 0; |
Nicolaemf | 6:b457f1e2fff8 | 27 | m_motorFw = 1; |
Nicolaemf | 6:b457f1e2fff8 | 28 | } |
Nicolaemf | 6:b457f1e2fff8 | 29 | else{ |
Nicolaemf | 6:b457f1e2fff8 | 30 | m_motorBw = 1; |
Nicolaemf | 6:b457f1e2fff8 | 31 | m_motorFw = 0; |
Nicolaemf | 6:b457f1e2fff8 | 32 | } |
Nicolaemf | 6:b457f1e2fff8 | 33 | |
Nicolaemf | 6:b457f1e2fff8 | 34 | |
Nicolaemf | 6:b457f1e2fff8 | 35 | m_prevDir = dir; |
Nicolaemf | 6:b457f1e2fff8 | 36 | |
Nicolaemf | 6:b457f1e2fff8 | 37 | } |
Nicolaemf | 6:b457f1e2fff8 | 38 | |
Nicolaemf | 6:b457f1e2fff8 | 39 | |
Nicolaemf | 7:b9c2097e5cb2 | 40 | void L298::SetSpeed(float speed){ |
Nicolaemf | 6:b457f1e2fff8 | 41 | /*set speed on the pwm which is point by m_pwmPtr (set by SetDirection) |
Nicolaemf | 6:b457f1e2fff8 | 42 | speed : the speed given to the motor, ranges from 0 to 1*/ |
Nicolaemf | 6:b457f1e2fff8 | 43 | |
Nicolaemf | 6:b457f1e2fff8 | 44 | if(speed<=0) m_motorEnable.write(0); |
Nicolaemf | 6:b457f1e2fff8 | 45 | else if(speed>=1.0)m_motorEnable.write(1.0); |
Nicolaemf | 6:b457f1e2fff8 | 46 | else m_motorEnable.write(speed); |
Nicolaemf | 6:b457f1e2fff8 | 47 | |
Nicolaemf | 6:b457f1e2fff8 | 48 | } |
Nicolaemf | 6:b457f1e2fff8 | 49 | |
Nicolaemf | 6:b457f1e2fff8 | 50 |