EasyManua.ls Logo

SunFounder 3in1 Kit - Page 241

Default Icon
351 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder 3in1 Kit
Code
Note:
Open the 2.move.ino file under the path of 3in1-kit\car_project\2.move.
Or copy this code into Arduino IDE.
After the code is uploaded, the car will move forward, backward, left and right for two seconds respectively.
How it works?
This project is essentially the same as the previous one, involving making the car move forward, backward, left, and
right, as well as stopping by providing different signal levels to the input pins of the L9110 module.
1. Initialize the pins of L9110 module.
const int A_1B = 5;
const int A_1A = 6;
const int B_1B = 9;
const int B_1A = 10;
void setup() {
pinMode(A_1B, OUTPUT);
pinMode(A_1A, OUTPUT);
pinMode(B_1B, OUTPUT);
pinMode(B_1A, OUTPUT);
}
2. Set the input pins to different high or low levels to control the rotation of the left and right motors, and then
encapsulate them in individual functions.
void moveForward() {
digitalWrite(A_1B, LOW);
digitalWrite(A_1A, HIGH);
digitalWrite(B_1B, HIGH);
digitalWrite(B_1A, LOW);
}
void moveBackward() {
digitalWrite(A_1B, HIGH);
digitalWrite(A_1A, LOW);
digitalWrite(B_1B, LOW);
digitalWrite(B_1A, HIGH);
}
...
3. Call these functions in loop().
void loop() {
moveForward();
delay(2000);
stopMove();
delay(500);
(continues on next page)
5.3. 2. Move by Code 237

Related product manuals