Skip to content

Instantly share code, notes, and snippets.

@chipchilders
Created January 7, 2014 20:36
Show Gist options
  • Save chipchilders/8306431 to your computer and use it in GitHub Desktop.
Save chipchilders/8306431 to your computer and use it in GitHub Desktop.
First pass at an RC car control program.
int pinI1=8;
int pinI2=11;
int speedpinA=9;
int pinI3=12;
int pinI4=13;
int speedpinB=10;
int speed =255;
int turnspeed =255;
void setup()
{
pinMode(pinI1,OUTPUT);
pinMode(pinI2,OUTPUT);
pinMode(speedpinA,OUTPUT);
pinMode(pinI3,OUTPUT);
pinMode(pinI4,OUTPUT);
pinMode(speedpinB,OUTPUT);
}
void forward()
{
analogWrite(speedpinB,speed);
digitalWrite(pinI4,HIGH);
digitalWrite(pinI3,LOW);
}
void backward()
{
analogWrite(speedpinB,speed);
digitalWrite(pinI4,LOW);
digitalWrite(pinI3,HIGH);
}
void left()
{
analogWrite(speedpinA,turnspeed);
digitalWrite(pinI2,LOW);
digitalWrite(pinI1,HIGH);
}
void right()
{
analogWrite(speedpinA,turnspeed);
digitalWrite(pinI2,HIGH);
digitalWrite(pinI1,LOW);
}
void straight()
{
analogWrite(speedpinA,speed);
digitalWrite(pinI2,LOW);
digitalWrite(pinI1,LOW);
}
void stop()
{
digitalWrite(speedpinA,LOW);
digitalWrite(speedpinB,LOW);
delay(1000);
}
void loop()
{
stop();
delay(2000);
forward();
delay(1000);
right();
delay(1000);
left();
delay(1000);
straight();
delay(2000);
stop();
delay(2000);
right();
backward();
delay(2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment