-
Notifications
You must be signed in to change notification settings - Fork 0
/
maina.ino
96 lines (94 loc) · 2.09 KB
/
maina.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#define l2r A4 // left sensor
#define l1r A3
#define cr A2
#define r1r A1
#define r2r A0
/*-------definning Outputs------*/
#define LM1 6 // left motor
#define LM2 7 // left motor
#define RM1 3 // right motor
#define RM2 4 // right motor
int k=400;
int d=3000;
void setup()
{
pinMode(l2r, INPUT);
pinMode(l1r, INPUT);
pinMode(cr, INPUT);
pinMode(r1r, INPUT);
pinMode(r2r, INPUT);
pinMode(LM1, OUTPUT);
pinMode(LM2, OUTPUT);
pinMode(RM1, OUTPUT);
pinMode(RM2, OUTPUT);
Serial.begin(9600);
}
void straight(){
digitalWrite(LM1, LOW);//straight//
digitalWrite(LM2, HIGH);
digitalWrite(RM1, LOW);
digitalWrite(RM2, HIGH);
}
void turnleft(){
digitalWrite(LM1, LOW);
digitalWrite(LM2, LOW);
digitalWrite(RM1, LOW);
digitalWrite(RM2, HIGH);
}
void turnright(){
digitalWrite(LM1, LOW);
digitalWrite(LM2, HIGH);
digitalWrite(RM1, LOW);
digitalWrite(RM2, LOW);
}
void uturn(){
turnright();
turnright();
}
void inch(){
digitalWrite(LM1, LOW);//straight//
digitalWrite(LM2, HIGH);
digitalWrite(RM1, LOW);
digitalWrite(RM2, HIGH);
delay(300);
}
void back(){
digitalWrite(LM1, LOW);//straight//
digitalWrite(LM2, HIGH);
digitalWrite(RM1, LOW);
digitalWrite(RM2, HIGH);
delay(300);}
int vic(int c,int l1,int l2,int r1,int r2){
inch();
if(c<k && l1<k &&l2<k &&r1<k&&r2<k){
return 1;
}
else{
return 0;}
}
void loop()
{
int l1=analogRead(l1r);
int l2=analogRead(l2r);
int c=analogRead(cr);
int r2=analogRead(r2r);
int r1=analogRead(r1r);
Serial.println(l1);
Serial.println(l2);
Serial.println(c);
Serial.println(r1);
Serial.println(r2);
if(c<k && l1>k && l2>k ) // Move Forward
{
straight();
}
if( l1<k || l2<k){
delay(1000);
turnleft();
}
if(c>k && l1>k && l2>k &&r1>k && r2>k){
delay(1000);
uturn();
}
//just reaches the goal state but donot detects it. Robot should be manually removed if it reaches goal
}