Created
January 7, 2014 20:36
-
-
Save chipchilders/8306431 to your computer and use it in GitHub Desktop.
First pass at an RC car control program.
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
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