Created
July 19, 2019 20:04
-
-
Save jonathanmv/5c8a01eeb72788972d95c703a3367f45 to your computer and use it in GitHub Desktop.
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
#include <AFMotor.h> | |
AF_DCMotor left(3); // This is M3 | |
AF_DCMotor right(4); // This is M4 | |
// Stops both wheels | |
void stop() { | |
left.run(RELEASE); | |
right.run(RELEASE); | |
} | |
void setup() | |
{ | |
left.setSpeed(120); | |
right.setSpeed(120); | |
} | |
void loop() { | |
delay(1000); | |
rotateLeft(90); | |
rotateRight(180); | |
rotateLeft(90); | |
} | |
/** | |
* speed 120 at 9v for 2.5s seems to make a reliable full circle | |
*/ | |
void xDegrees(float x) { | |
int fullCircle = 2500; | |
delay(fullCircle * (x/360.0)); | |
} | |
void rotateLeft(int degrees) { | |
// Stop left wheel | |
left.run(RELEASE); | |
// Start right wheel forward | |
right.run(FORWARD); | |
// Wait until the car has reached some degrees | |
xDegrees(degrees); | |
stop(); | |
} | |
void rotateRight(int degrees) { | |
// Stop left wheel | |
left.run(RELEASE); | |
// Start right wheel backwards | |
right.run(BACKWARD); | |
xDegrees(degrees); | |
stop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment