EasyManua.ls Logo

SunFounder 3in1 Kit - Follow the Line

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
1. Use the for() statement to give speed in steps of 5, writing values from 0 to 255 so you can see the change in
the car’s forward speed.
void loop() {
for(int i=0;i<=255;i+=5){
moveForward(i);
delay(500);
}
for(int i=255;i>=0;i-=5){
moveForward(i);
delay(500);
}
}
2. About the moveForward() function.
As opposed to 2. Move by Code which directly gives high/low levels to the input pins of the L9110
module, here we pass a parameter speed to where we need to give high levels.
void moveForward(int speed) {
analogWrite(A_1B, 0);
analogWrite(A_1A, speed);
analogWrite(B_1B, speed);
analogWrite(B_1A, 0);
}
for
The for statement is used to repeat a block of statements enclosed in curly braces. An increment counter is usually
used to increment and terminate the loop.
for (initialization; condition; increment) {
// statement(s);
}
initialization: happens first and exactly once.
condition: each time through the loop, condition is tested; if it’s true, the statement block, and the
increment is executed, then the condition is tested again. When the condition becomes false, the loop
ends.
increment: executed each time through the loop when condition is true.
5.5 4. Follow the line
The car is equipped with a Line Track module, which can be used to make the car follow the black line.
When the line following module detects the black line, the right motor rotates while the left motor does not, so that the
car moves one step to the left front. As the car moves, the line module will be moved out of the line, then the left motor
turns and the right motor does not turn, the car will move one step to the right to return to the line. Repeat the above
two steps, the car can move along the black line.
Before starting the project, you need to build a curve map with black line tape, the recommended line width is between
0.8-1.5cm and the angle of the turn should not be less than 90 degrees.
Required Components
5.5. 4. Follow the line 239

Related product manuals