Created
March 20, 2017 06:09
-
-
Save elktros/df71b575474f6ae96e3edcc149d30302 to your computer and use it in GitHub Desktop.
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 mot1=9; | |
int mot2=6; | |
int mot3=5; | |
int mot4=3; | |
int left=13; | |
int right=12; | |
int Left=0; | |
int Right=0; | |
void LEFT (void); | |
void RIGHT (void); | |
void STOP (void); | |
void setup() | |
{ | |
pinMode(mot1,OUTPUT); | |
pinMode(mot2,OUTPUT); | |
pinMode(mot3,OUTPUT); | |
pinMode(mot4,OUTPUT); | |
pinMode(left,INPUT); | |
pinMode(right,INPUT); | |
digitalWrite(left,HIGH); | |
digitalWrite(right,HIGH); | |
} | |
void loop() | |
{ | |
analogWrite(mot1,255); | |
analogWrite(mot2,0); | |
analogWrite(mot3,255); | |
analogWrite(mot4,0); | |
while(1) | |
{ | |
Left=digitalRead(left); | |
Right=digitalRead(right); | |
if((Left==0 && Right==1)==1) | |
LEFT(); | |
else if((Right==0 && Left==1)==1) | |
RIGHT(); | |
} | |
} | |
void LEFT (void) | |
{ | |
analogWrite(mot3,0); | |
analogWrite(mot4,30); | |
while(Left==0) | |
{ | |
Left=digitalRead(left); | |
Right=digitalRead(right); | |
if(Right==0) | |
{ | |
int lprev=Left; | |
int rprev=Right; | |
STOP(); | |
while(((lprev==Left)&&(rprev==Right))==1) | |
{ | |
Left=digitalRead(left); | |
Right=digitalRead(right); | |
} | |
} | |
analogWrite(mot1,255); | |
analogWrite(mot2,0); | |
} | |
analogWrite(mot3,255); | |
analogWrite(mot4,0); | |
} | |
void RIGHT (void) | |
{ | |
analogWrite(mot1,0); | |
analogWrite(mot2,30); | |
while(Right==0) | |
{ | |
Left=digitalRead(left); | |
Right=digitalRead(right); | |
if(Left==0) | |
{ | |
int lprev=Left; | |
int rprev=Right; | |
STOP(); | |
while(((lprev==Left)&&(rprev==Right))==1) | |
{ | |
Left=digitalRead(left); | |
Right=digitalRead(right); | |
} | |
} | |
analogWrite(mot3,255); | |
analogWrite(mot4,0); | |
} | |
analogWrite(mot1,255); | |
analogWrite(mot2,0); | |
} | |
void STOP (void) | |
{ | |
analogWrite(mot1,0); | |
analogWrite(mot2,0); | |
analogWrite(mot3,0); | |
analogWrite(mot4,0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment