To build a toy car that can be controlled using switches. By having the wheels spin at different speeds, the vehicle's motion can be controlled.
CIRCUIT DIAGRAM
CODE
void setup()
{
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(6, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
}
void loop()
{
digitalRead(2);
digitalRead(3);
digitalRead(4);
digitalRead(5);
digitalRead(7);
digitalRead(8);
if (digitalRead(2) == 1) // FORWARD
{
digitalWrite(6, HIGH);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
}
else
{
if (digitalRead(3) == 1)// BACKWARD
{
digitalWrite(6, LOW);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
}
else
{
if (digitalRead(4) == 1) // SMOOTH LEFT
{
analogWrite(6, 100);
analogWrite(11, 0);
analogWrite(10, 1000);
analogWrite(9, 0);
}
else
{
if (digitalRead(5) == 1) // SMOOTH RIGHT
{
analogWrite(6, 1000);
analogWrite(11, 0);
analogWrite(10, 100);
analogWrite(9, 0);
}
else
{
if (digitalRead(7) == 1) // SHARP LEFT
{
digitalWrite(6, LOW);
digitalWrite(10, LOW);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
}
else
{
if (digitalRead(8) == 1)// SHARP RIGHT
{
digitalWrite(6, HIGH);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
}
else // STOP
{
digitalWrite(6, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
}
}
}
}
}
}
delay(10);
}
Comentarios