Commit 0f34802f authored by Brandon Fan's avatar Brandon Fan 💬
Browse files

add main_working with checks

parent 2cb243e9
......@@ -59,8 +59,25 @@ void print_sensors(long * data) {
Serial.println();
}
long average(long a, long b) {
return (a + b) / 2;
}
bool check_against(long a, long b, long comp) {
long avg = average(a, b);
return abs(avg - comp) > 30;
}
void loop() {
long data[3];
read_inputs(data);
print_sensors(data);
bool check_right = check_against(data[0], data[1], data[2]);
bool check_left = check_against(data[1], data[2], data[0]);
bool check_mid = check_against(data[0], data[2], data[1]);
if (check_right || check_left || check_mid) {
Serial.println("There seems to be an object in the way...");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment