Created
March 30, 2018 23:30
-
-
Save zr0n/2d4fb984f32087f468acce381d3613c4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
#define SPEED 255 | |
AF_DCMotor leftWheels(1); | |
AF_DCMotor rightWheels(2); | |
unsigned char serialData = 0x00; | |
void setup(){ | |
Serial.begin(9600); | |
setSpeed(); | |
} | |
void loop(){ | |
if(Serial.available() > 0){ | |
serialData = Serial.read(); | |
switch(serialData){ | |
case 48: | |
stop(); | |
break; | |
case 49: | |
goForward(); | |
break; | |
case 50: | |
goBackward(); | |
break; | |
case 51: | |
turnLeft(); | |
break; | |
case 52: | |
turnRight(); | |
break; | |
} | |
} | |
} | |
void setSpeed(){ | |
leftWheels.setSpeed(SPEED); | |
rightWheels.setSpeed(SPEED); | |
} | |
void turnLeft(){ | |
rightWheels.run(FORWARD); | |
leftWheels.run(RELEASE); | |
} | |
void turnRight(){ | |
leftWheels.run(FORWARD); | |
rightWheels.run(RELEASE); | |
} | |
void goBackward(){ | |
leftWheels.run(BACKWARD); | |
rightWheels.run(BACKWARD); | |
} | |
void goForward(){ | |
leftWheels.run(FORWARD); | |
rightWheels.run(FORWARD); | |
} | |
void stop(){ | |
leftWheels.run(RELEASE); | |
rightWheels.run(RELEASE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment