Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
examples/Car/SimpleCarWithDualMotors/SimpleCarWithDualMotors.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <Smartcar.h> | ||
|
||
ArduinoRuntime arduinoRuntime; | ||
const BrushedMotorPins leftFrontMotorPins{ 12, 14, 13 }; | ||
const BrushedMotorPins leftRearMotorPins{ 22, 24, 23 }; | ||
const BrushedMotorPins rightFrontMotorPins{ 25, 26, 27 }; | ||
const BrushedMotorPins rightRearMotorPins{ 32, 34, 33 }; | ||
|
||
BrushedMotor leftFrontMotor{ arduinoRuntime, leftFrontMotorPins }; | ||
BrushedMotor leftRearMotor{ arduinoRuntime, leftRearMotorPins }; | ||
BrushedMotor rightFrontMotor{ arduinoRuntime, rightFrontMotorPins }; | ||
BrushedMotor rightRearMotor{ arduinoRuntime, rightRearMotorPins }; | ||
|
||
DualMotor leftMotor{ leftFrontMotor, leftRearMotor }; | ||
DualMotor rightMotor{ rightFrontMotor, rightRearMotor }; | ||
|
||
DifferentialControl control{ leftMotor, rightMotor }; | ||
|
||
SimpleCar car{ control }; | ||
|
||
void setup() | ||
{ | ||
// Move forward for 3 seconds | ||
car.setSpeed(50); | ||
delay(3000); | ||
// Start turning sharp left | ||
car.setAngle(-90); | ||
delay(3000); | ||
// Straighten the car and move backward | ||
car.setAngle(0); | ||
car.setSpeed(-50); | ||
delay(3000); | ||
car.setSpeed(0); | ||
} | ||
|
||
void loop() {} |