Skip to content

Commit

Permalink
Add DualMotors example sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
platisd committed Mar 12, 2023
1 parent 4af661c commit c07b3c8
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions examples/Car/SimpleCarWithDualMotors/SimpleCarWithDualMotors.ino
@@ -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() {}

0 comments on commit c07b3c8

Please sign in to comment.