-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch_mar30b.ino
52 lines (45 loc) · 1.06 KB
/
sketch_mar30b.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
# include <SmartInventor.h>
void setup() {
// put your setup code here, to run once:
SmartInventor.Buzz(NOTE_C5, 16);
delay(5000);
pinMode(11, INPUT);
pinMode(18, INPUT);
SmartInventor.DCMotorUse();
}
void loop() {
// put your main code here, to run repeatedly:
int leftSensor = digitalRead(11);
int rightSensor = digitalRead(18);
if (leftSensor == LOW)
{
//backup
SmartInventor.DCMotor(M1, CW, 50);
SmartInventor.DCMotor(M2, CCW, 50);
delay(644);
//turn right
SmartInventor.DCMotor(M1, CW, 80);
SmartInventor.DCMotor(M2, CW, 80);
delay(550);
}
// if right sees line, backup and turn left
// otherwise go forward
else if (rightSensor == LOW)
{
//backup
SmartInventor.DCMotor(M1, CW, 50);
SmartInventor.DCMotor(M2, CCW, 50);
delay(644);
//turn left
SmartInventor.DCMotor(M1, CCW, 80);
SmartInventor.DCMotor(M2, CCW, 80);
delay(550);
}
// otherwise go forward
else
{
// forward
SmartInventor.DCMotor(M1, CCW, 80);
SmartInventor.DCMotor(M2, CW, 80);
}
}