-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsensot2.ino
More file actions
executable file
·81 lines (66 loc) · 1.53 KB
/
sensot2.ino
File metadata and controls
executable file
·81 lines (66 loc) · 1.53 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
#include "MeOrion.h"
MeUltrasonicSensor ultraSensor(PORT_3);
MeDCMotor rightMotor(M1);
MeDCMotor leftMotor(M2);
int motorSpeed = 106;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
int x = 0;
boolean stopped = false;
void loop() {
// put your main code here, to run repeatedly:
x = ultraSensor.distanceCm();
delay(100);
stop_before(x,60);
}
void stop_before(int x,int distance){
if (x == 0 or x>distance){
leftMotor.run(-motorSpeed);
rightMotor.run(motorSpeed);
}
else {
rightMotor.run(-motorSpeed);
}
}
/*
boolean scan_area()
{
rightMotor.run(motorSpeed);//rotate clockwise
leftMotor.run(-motorSpeed);
int y = 0
for(int j = 0;j<5;j++){
Y = ultraSensor.distanceCm();
if (y = 0 and y<distance){
return false;}
delay(100);
rightMotor.run(-motorSpeed);//rotate counterclockwise
leftMotor.run(motorSpeed);
for(int j = 0;j<10;j++){
Y = ultraSensor.distanceCm();
if (x = 0 and x<distance){
rightMotor.run(motorSpeed);//rotate clockwise
leftMotor.run(-motorSpeed);
delay(300);
return false;}
delay(100);
rightMotor.stop();//rotate counterclockwise
leftMotor.stop();
return True;
}
}*/
boolean turn_45()
{
rightMotor.run(motorSpeed);//rotate clockwise
leftMotor.run(-motorSpeed);
int y = 0;
for(int j = 0;j<10;j++){
y = ultraSensor.distanceCm();
if (y != 0 and y<45){
return true;
}
delay(100);
}
return false;
}