-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesterino.nxc
100 lines (89 loc) · 3 KB
/
testerino.nxc
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
task main() {
string color_str; //string to display color on monitor for debugging
int n,e,s,w;
SetSensorColorFull(IN_1); //turn rbg sensor on
while (true) {
if (Sensor(IN_1) == 1){ // check if rgb sensor read "black"
color_str = "Black";
until (Sensor(IN_1) != 1) {
OnFwd(OUT_AC, 30); // move forward with an output power of 30
}
Off(OUT_AC); // stop motors to read the next color
}
else if (Sensor(IN_1) == 2){ //check if rgb sensor read "blue"
color_str = "Blue";
OnRev(OUT_AC, 15);
Wait(100);
Off(OUT_AC);
while (Sensor(IN_1) == 2) {
OnFwd(OUT_A, 30);
OnRev(OUT_C, 30);
}
Off(OUT_AC);
}
else if (Sensor(IN_1) == 3){ //check if rgb sensor read "blue"
color_str = "Blue";
while (Sensor(IN_1) == 2) {
OnFwd(OUT_A, 30);
OnRev(OUT_C, 30);
}
Off(OUT_AC);
}
else if (Sensor(IN_1) == 6){ //check if rgb sensor read "white"
color_str = "White";
while (Sensor(IN_1) == 2) {
OnFwd(OUT_A, 30);
OnRev(OUT_C, 30);
}
Off(OUT_AC);
}
else if (Sensor(IN_1) == 4){ //check if rgb sensor read "yellow"
color_str = "Yellow";
// collect color that is ahead of me
OnFwd(OUT_AC, 20);
Wait(100);
Off(OUT_AC);
n = Sensor(IN_1); // store color at the north value
TextOut(0, 0, NumToStr(n)); // display current color on the monitor
// reset position
until (Sensor(IN_1) == 4) {
OnRev(OUT_AC, 20);
}
Off(OUT_AC);
// collect color that is to the left of me
// turn left 90 degrees
OnFwd(OUT_C, 75);
OnRev(OUT_A, 75);
Wait(1050);
Off(OUT_AC);
// move forward to collect color
OnFwd(OUT_AC, 20);
Wait(100);
Off(OUT_AC);
w = Sensor(IN_1);
// reset position
OnRev(OUT_AC, 20);
Wait(100);
Off(OUT_AC);
// collect color that is to the right of me and continue
OnFwd(OUT_A, 75); // rotate clockwise 180 degrees
OnRev(OUT_C, 75);
Wait(2100);
Off(OUT_AC); // stop motor to read the next color
OnFwd(OUT_AC, 20);
Wait(100);
e = Sensor(IN_1);
Off(OUT_AC);
}
TextOut(0, 0, color_str); // display current color on the monitor
}
}
/*
future todos:
implement current code into starter code ;)
figure out sound function with a functional nxt
cover up the light sensor with a piece of paper
navigate to the center
keep track of places that have been to
read green/blue as buildings
*/