// this project only deals with direction control of the toy car
// every dc motor has two states 'ON' and 'OFF'
int mot1; // right side rear motor
int mot2; // left side rear motor
int x;
int y;
void setup() {
Serial.begin(115200);
// both motors are 'OFF'
mot1 = 0;
mot2 = 0;
}
void forward(){
mot1 = 1;
mot2 = 1;
// both motors 'ON' will move the toy car forward
}
void right(){
mot1 = 0;
mot2 = 1;
// left side motor 'ON' will turn the toy car right
}
void left(){
mot1 = 1;
mot2 = 0;
// rigth side motor 'ON' will turn the toy car left
}
void loop() {
x = analogRead(A0);
y = analogRead(A1);
if(x < 200){
forward();
Serial.println("forward");
}
else{
if (y < 200){
left();
Serial.println("left");
}
else if (y > 800){
right();
Serial.println("right");
}
}
}