-
Notifications
You must be signed in to change notification settings - Fork 0
Basic Movement
-
Including the Car Control Library
#include "CarControl.h"
This line is like telling the Arduino, "Hey, we're going to need the set of instructions you have for controlling the car!" π
-
Setting Up the Car
CarControl car(5, 6, 7, 8, 3, 2);
Here, we're creating our car and telling the Arduino which pins are connected to the car's motors. ποΈ
-
The Setup Function
void setup() { car.setup(); // Initialize the car }
This function is called once when the Arduino first starts up. It's like the car is waking up and getting ready for a drive! πβ‘οΈπ
-
The Loop Function - Where the Magic Happens!
void loop() { int speed = 255; // Fastest speed! car.moveForward(speed, 2000); // Zoom forward delay(1000); // Wait for 1 second car.moveBackward(speed, 2000); // Zoom backward delay(1000); // Wait for 1 second car.turnLeft(speed, 2000); // Turn left delay(1000); // Wait for 1 second car.turnRight(speed, 2000); // Turn right delay(1000); // Wait for 1 second car.turnAround(); // Do a 180! delay(1000); // Wait for 1 second }
In this part, we're telling the car exactly what to do! We set a speed, then we have a series of commands telling the car to move forward, backward, turn left, turn right, and do a 180-degree turn, with short breaks in between each action. It's like a dance routine for the car! ππΊπ
And that's it! Now you know how this program makes the car move around. π