-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtable_top.cpp
More file actions
109 lines (90 loc) · 2.09 KB
/
table_top.cpp
File metadata and controls
109 lines (90 loc) · 2.09 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* table_top.cpp
*
* Created: 4/6/2016
* Author: Simran Suresh
*/
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRD = 0b00000000; //Assigning Port D as input port
DDRB = 0b11111111; //Assigning Port B as output port
PORTD = 0b11111111; //Pulling up the values of all the pins of port D
int c;
while(1)
{
c = PIND; //Read only register PIND
if(c==0b11110000) //All sensors are on the table
{
PORTB = 0b00001010; //Move forward
_delay_ms(50);
PORTB = 0b00000000; //Stop for 5 ms
_delay_ms(50);
}
if(c==0b11111000) //Sensor 1 is OUT OF THE TABLE
{
PORTB=0b00011001; //Turn Right
_delay_ms(200);
}
if(c==0b11110100) //Sensor 2 is OUT OF THE TABLE
{
PORTB=0b00010110; //Turn left
_delay_ms(200);
}
if(c==0b11110010) //Sensor 3 is OUT OF THE TABLE
{
PORTB=0b00010110; //Turn left
_delay_ms(200);
}
if(c==0b11110001) //Sensor 4 is out of the table
{
PORTB=0b00011001; //Turn right
_delay_ms(200);
}
if(c==0b11111100) //Sensors 1 & 2 are OUT OF THE TABLE
{
PORTB=0b00010101; //Move back
_delay_ms(200);
PORTB=0b00011001; //Turn right
_delay_ms(200);
}
if(c==0b11111001) //Sensors 1 & 4 are OUT OF THE TABLE
{
PORTB=0b00011001; //Turn right
_delay_ms(250);
}
if(c==0b11110011) //Sensors 3 & 4 are OUT OF THE TABLE
{
PORTB=0b00011010; //Move forward
_delay_ms(200);
PORTB=0b00011001; //Turn right
}
if(c==0b11110110) //Sensors 2 & 3 are OUT OF THE TABLE
{
PORTB=0b00010110; //Move left
_delay_ms(200);
}
if(c==0b11111110) //Sensors 1,2 & 3 are OUT OF THE TABLE
{
PORTB=0b00010110; //Long Left Turn
_delay_ms(700);
}
if(c==0b11111101) //Sensors 1,2 & 4 are OUT OF THE TABLE
{
PORTB=0b00010110; //Long Right Turn
_delay_ms(700);
}
if(c==0b11111011) //Sensors 1,3 & 4 are OUT OF THE TABLE
{
PORTB=0b00011001; //Long Right Turn
_delay_ms(700);
}
if(c==0b11110111) //Sensors 2,3 & 4 are OUT OF THE TABLE
{
PORTB=0b00010110; //Long LEFT U Turn
_delay_ms(700);
}
}
}