-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_test.cpp
96 lines (81 loc) · 2.54 KB
/
build_test.cpp
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
#include <Arduino.h>
#include <compkit.h>
compkit::color_sensor<5> color_reader(13, 12, 14, 27);
compkit::engine engine(32, 33);
compkit::engine_controller controller(32, 33, 34, 35);
void menu(String incomingString) {
// say what you got:
Serial.print("Foi recebido: ");
Serial.println(incomingString);
if (incomingString == "t" || incomingString == "test") {
Serial.println("Função 'teste' reconhecida!");
Serial.println("Hello World!");
for (int i = 0; i < 3; i++) {
analogWrite(13, 1023);
delay(50);
analogWrite(13, 0);
delay(50);
}
Serial.println("Função 'teste' terminada!");
} else if (incomingString == "c" || incomingString == "addc") {
Serial.println("Função 'add color point' reconhecida!");
int red, green, blue, natural;
color_reader.read(red, green, blue, natural);
Serial.print("Red: ");
Serial.print(red);
Serial.print(" | Green: ");
Serial.print(green);
Serial.print(" | Blue: ");
Serial.print(blue);
Serial.print(" | Natural: ");
Serial.println(natural);
int count = color_reader.add_color_point(red, green, blue, natural);
if (count >= 4) {
Serial.println("Max Color Points Reached!");
incomingString == "q";
}
Serial.println("Função 'add color point' terminada!");
} else if (incomingString == "q" || incomingString == "quit") {
Serial.println("Função 'quit' reconhecida!");
Serial.println("Encerrando o programa de calibração...");
}
else {
Serial.println("Função Desconhecida!");
}
Serial.println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
}
void setup() {
Serial.begin(115200);
String incomingString = "";
while (incomingString != "quit" && incomingString != "q") {
if (Serial.available() > 0) {
incomingString = Serial.readStringUntil('\n');
menu(incomingString);
}
}
}
void loop() {
int red, green, blue, natural;
color_reader.read(red, green, blue, natural);
Serial.print("Red: ");
Serial.print(red);
Serial.print(" | Green: ");
Serial.print(green);
Serial.print(" | Blue: ");
Serial.print(blue);
Serial.print(" | Natural: ");
Serial.print(natural);
int color = color_reader.closest_color(red, green, blue, natural);
if (color == 0) {
Serial.println(" | Color: Red");
} else if (color == 1) {
Serial.println(" | Color: Green");
} else if (color == 2) {
Serial.println(" | Color: Blue");
} else if (color == 3) {
Serial.println(" | Color: Yellow");
} else {
Serial.println(" | Color: White");
}
delay(200);
}