forked from sevenmatt7/maze-champ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ultrasound & IR.txt
51 lines (38 loc) · 1.28 KB
/
Ultrasound & IR.txt
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
#define TIMEOUT 30000
#define WAITING_TIME 1000
#define ULTRASONIC 12
#define LEFT_IR
#define RIGHT_IR
// If you are using PORT 1 of the mCore, the ultrasonic sensor is connected to digital pin 12
// If you are using PORT 2 of the mCore, the ultrasonic sensor is connected to digital pin 10
void setup() {
// Set up serial communication
Serial.begin(9600);
}
void loop() {
// The following code runs repeatedly:
pinMode(ULTRASONIC, OUTPUT);
pinMode(LEFT_IR, INPUT);
pinMode(RIGHT_IR, INPUT);
digitalWrite(ULTRASONIC, LOW);
delayMicroseconds(2);
digitalWrite(ULTRASONIC, HIGH);
delayMicroseconds(2);
digitalWrite(ULTRASONIC, LOW);
pinMode(ULTRASONIC, INPUT);
long duration = pulseIn(ULTRASONIC, HIGH, TIMEOUT);
//need to find the analogReadvalue for 6cm and below and when it gets below this number, it will shift
long left_distance = analogRead(LEFT_IR);
long right_distance = analogRead(RIGHT_IR);
if (left_distance < 5cm) {
//shift right
} if (right_distance < 5cm {
//shift left
}
if (front_distance < 5cm) {
//stop and call the function for colour sensing challenge
Serial.print("Duration: ");
Serial.print(duration);
Serial.println(" microseconds");
delay(WAITING_TIME);
}