-
Notifications
You must be signed in to change notification settings - Fork 82
/
RobotProject2019.ino
166 lines (143 loc) · 4.95 KB
/
RobotProject2019.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//CodeSpace Template
//***DO NOT EDIT includes and declarations***
//include libraries
#include <Servo.h>
#include <IRremote.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
//IR initiate
const int RECV_PIN = 7; IRrecv irrecv(RECV_PIN); decode_results results;
//Declare servos
Servo rightWheel; Servo leftWheel;
//declare PING input/output
const int trigPin = 5; const int echoPin = 6;
//End of template includes
void setup()
{
//Assign servo digital pins
rightWheel.attach(2);
leftWheel.attach(3);
lcd.begin(16,2); lcd.setCursor(1,0);
irrecv.enableIRIn();
//end of template setup
//LIGHT VERIFICATION SETUP:
pinMode(11, OUTPUT);//Left Light
pinMode(12, OUTPUT);//Right Light
pinMode(13, OUTPUT);//Used to indicate that drive is over
}
void loop()
{
// put your main code below here, to run repeatedly:
if (irrecv.decode(&results)) //Searches for remote signal. Any button pressed is then recorded and relayed into loop.
{
if (results.value == 0xFF18E7)// Hexadecimal for Up Button. Code checks for presence of "Up" button.
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Driving Forward"); // Verification of movement
leftWheel.writeMicroseconds(2000);
rightWheel.writeMicroseconds(1000);
delay(715); //Decreased speed from 1000
rightWheel.writeMicroseconds(1500);
leftWheel.writeMicroseconds(1500);
}
irrecv.resume();
if (results.value == 0xFF629D)// Press "2". Backup to move forward
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Driving Forward"); // Verification of movement
leftWheel.writeMicroseconds(1000);
rightWheel.writeMicroseconds(2000);
delay(1000);
rightWheel.writeMicroseconds(1500);
leftWheel.writeMicroseconds(1500);
}
irrecv.resume();
//Stopping Indicator
if(results.value == 0xFF9867) //Press "0". Only used because we forgot to press the OK button during testing
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Stopped"); // Verification of halting movement
leftWheel.writeMicroseconds(1500);
rightWheel.writeMicroseconds(1500);
//<---Lights--->
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);//Intended to switch on all lights simultaneously
delay(1000);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);// Intended to switch off all lights simultaneously
}
irrecv.resume();
//Left Turn
if(results.value == 0xFF22DD) //Press "4" Button
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Moving Left"); //Used to move robot leftward
leftWheel.writeMicroseconds(1000);
rightWheel.writeMicroseconds(1000);
digitalWrite(11, HIGH); // Turn on the LED light to indicate left turn
delay(425);
rightWheel.writeMicroseconds(1500);
leftWheel.writeMicroseconds(1500);
digitalWrite(11, LOW); // Switches off LED Light
}
irrecv.resume();
/*Minor Left Turn
* Button used for precautional methods as experiment revealed that tighter turns are existant within maze.
* Press Number 1
*/
if(results.value == 0xFFA25D)//Turns slightly left
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Moving Slightly Left") //Moves Slightly Left
leftWheel.writeMicroseconds(1000);
rightWheel.writeMicroseconds(1000);
digitalWrite(11, HIGH); // Turns on LED Light
delay(225);
rightWheel.writeMicroseconds(1500);
leftWheel.writeMicroseconds(1500);
digitalWrite(11, LOW);// Switches off LED Light
}
irrecv.resume();
//Right Turn
if(results.value == 0xFFC23D) //Press "6" Button
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Moving Right"); //Used to move robot leftward
leftWheel.writeMicroseconds(2000);
rightWheel.writeMicroseconds(2000);
digitalWrite(12, HIGH); // Turn on the LED light to indicate right turn
delay(425);
rightWheel.writeMicroseconds(1500);
leftWheel.writeMicroseconds(1500);
digitalWrite(12, LOW); // Switches off LED Light
}
irrecv.resume();
/* Minor Right Turn
* Press "3" Button
*/
if (results.value == 0xFFE21D)
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Moving Slightly Right"); //Used to move slightly right
leftWheel.writeMicroseconds(2000);
rightWheel.writeMicroseconds(2000);
digitalWrite(12, HIGH); // Turn on the LED Light to indicate right turn or slightly so
delay(225);
rightWheel.writeMicroseconds(1500);
leftWheel.writeMicroseconds(1500);
digitalWrite(12, LOW); // Switches off LED Light
}
irrecv.resume();
}
delay(10);//Delay Timer for entire code process. After 10 milliseconds, robot will become responsive
}