Skip to content

Basic Movement

Fred Feraco edited this page Oct 24, 2023 · 2 revisions

🏎️ Let's talk about how this small car is controlled using Arduino! 🏎️

  1. 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!" πŸ“œ

  2. 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. πŸŽ›οΈ

  3. 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! πŸ›Œβž‘οΈπŸš—

  4. 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. 😊

Clone this wiki locally