To support the robo car, this class makes it easier to tell the car what you want it to do. It elminates the need to specify pins and all the complicated stuff of the Arduino hardware interface (that's all encapsulated in the ElegooCar class).
If you are not using the PlatformIO IDE for VS Code, you really should be. The ecosystem and convention-base approach they have developed for building and uploading code to devices is really smooth. This library follows their directory structure convention.
Take a short while to familiarize yourself with this editor. You will be way more productive and happy using it over the Arduino editor (which they shamefully call an IDE). PlatformIO IDE is practically zero configuration to get it up and running.
You will notice that the examples/demo.cpp has a .cpp
(C++ language) extension, not a .ino
(Arduino) extension. This is to make IntelliSense in VS Code work for you. See explanation here. All .ino
files are compiled to C++ under the hood anyway.
A demo of some of the features of this ElegooCar
library exists in examples/demo.cpp. To try out this demo, you need to copy it to your ./src
directory. The PlatformIO build/upload system will only recognize files under your /.src
directory.
If you are using PlatformIO (as you should be), it is very simple to use this (or any) library. In your project directyory, edit the file platformio.ini
to add this lib_deps
line to the [env:uno]
section:
[env:uno]
lib_deps =
https://github.com/btmurrell/elegoocar.git
Save the file. Then proceed with the example and APIs below. When you build your project, it will bring this library in automatically to your system. That's it!
To use the API, be sure you include the header and an instance at the top. Do not put it in your setup() method. Put it at the top of your .cpp
file:
#include <elegoo_car.h>
ElegooCar car;
After that, you can use the car
instance in your code, according to the API below.
In the APIs below, the int speed
parameter is the speed you want the car (or wheels) to move in. This speed number is a relative number (not a miles per hour!). The range of valid values is 70 to 255. Below 70 does not pull enough juice from the batteries to power the motors. The int duration
optional parameter is the amount of time in miliseconds that you want the car to make that movement.
The forward
method will move the car forward at the given speed, for the given duration in miliseconds. You may omit the duration parameter, which will cause the car to continue this motion until another command is given.
The reverse
method will move the car in reverse at the given speed, for the given duration in miliseconds. You may omit the duration parameter, which will cause the car to continue this motion until another command is given.
The stop
method will make all the wheels on the car stop for the specified duration in miliseconds. You may omit the duration parameter, which will cause the car to continue this motion until another command is given.
The fwdRight
method will move the car in a forward, right direction, at the given speed for the given duration in milliseconds. You may omit the duration parameter, which will cause the car to continue this motion until another command is given.
The fwdLeft
method will move the car in a forward, left direction, at the given speed for the given duration in milliseconds. You may omit the duration parameter, which will cause the car to continue this motion until another command is given.
The backRight
method will move the car in a backward, right direction, at the given speed for the given duration in milliseconds. You may omit the duration parameter, which will cause the car to continue this motion until another command is given.
The backLeft
method will move the car in a backward, left direction, at the given speed for the given duration in milliseconds. You may omit the duration parameter, which will cause the car to continue this motion until another command is given.