Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int a,b,c,d,e,m;
- #define left 1
- #define right 0
- #define f 60
- #define F 1
- #define B 0
- void motors(int d1,int s1,int d2,int s2)
- {
- analogWrite(2,s1*!d1);
- analogWrite(3,s1*d1);
- analogWrite(8,s2*d2);
- analogWrite(9,s2*!d2);
- }
- void linefollower()
- {
- a=digitalRead(48);
- b=digitalRead(46);
- c=digitalRead(44);
- d=digitalRead(42);
- e=digitalRead(40);
- m=(a<<4)+(b<<3)+(c<<2)+(d<<1)+e;
- }
- int findLine(int dir)
- {
- motors(F*!dir,f,F*dir,f);
- delay(100);
- linefollower();
- while (!c)
- linefollower();
- }
- bool readCol(int sensor)
- {
- return 0; //mo2akkatan
- }
- void intersection2(int dep)
- {
- bool a=readCol(right),B=readCol(left);
- if (a && b)
- {
- motors(F,f,B,f);
- delay(200);
- while (!c)
- motors(F,f,B,f);
- motors(F,f,F,f);
- }
- else if (a && !b)
- {
- motors(F,f,F,f);
- delay(100);
- findLine(left);
- }
- else if (!a && b)
- {
- motors(F,f,F,f);
- delay(100);
- findLine(right);
- }
- else if (dep<3)
- {
- motors(B,f,B,f);
- delay(50);
- intersection2(dep+1);
- }
- }
- void intersection(int dir)
- {
- if (readCol(dir))
- findline(dir);
- else
- {
- motors(F,f,F,f);
- delay(100);
- linefollower();
- if (!m)
- findLine(dir);
- else
- motors(F,f,F,f);
- }
- }
- void setup()
- {
- Serial.begin(9600);
- pinMode(2,OUTPUT);
- pinMode(3,OUTPUT);
- pinMode(8,OUTPUT);
- pinMode(9,OUTPUT);
- pinMode(48,INPUT);
- pinMode(46,INPUT);
- pinMode(44,INPUT);
- pinMode(42,INPUT);
- pinMode(40,INPUT);
- }
- void loop()
- {
- linefollower();
- if (m==0b00000)
- motors(F,f,F,f);
- else if (m==0b00001)
- findLine(left);
- else if (m==0b00010)
- findLine(left);
- else if (m==0b00011)
- intersection(right);
- else if (m==0b00100)
- motors(F,f,F,f);
- else if (m==0b00101)
- intersection(right);
- else if (m==0b00110)
- intersection(right);
- else if (m==0b00111)
- intersection(right);
- else if (m==0b10000)
- findLine(right);
- else if (m==0b01000)
- findLine(left);
- else if (m==0b11000)
- intersection(left);
- else if (m==0b10100)
- intersection(left);
- else if (m==0b01100)
- intersection(left);
- else if (m==0b11100)
- intersection(left);
- else
- intersection2(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement