Commit 34661c23 authored by Brandon Fan's avatar Brandon Fan 💬
Browse files

add documentation

parent e4548f47
......@@ -22,10 +22,12 @@ void setup() {
Serial.begin(9600); // Starts the serial communication
}
// Calculates the distance by converting sound into centimeters
long calculate_distance(long duration) {
return duration * 0.034 / 2;
}
// Reads the ultrasound given a specific trig and echo pin
long read_pin(int trig_pin, int echo_pin, int start_microseconds, int end_microseconds) {
digitalWrite(trig_pin, LOW);
delayMicroseconds(start_microseconds);
......@@ -38,6 +40,7 @@ long read_pin(int trig_pin, int echo_pin, int start_microseconds, int end_micros
return pulseIn(echo_pin, HIGH);
}
// Reads inputs from all the pins and outputs to a datapoints array
void read_inputs(long * datapoints) {
long duration_left = read_pin(trig_pin_left, echo_pin_left, 2, 10);
datapoints[0] = calculate_distance(duration_left);
......@@ -49,6 +52,7 @@ void read_inputs(long * datapoints) {
datapoints[2] = calculate_distance(duration_right);
}
// Prints the sensor data
void print_sensors(long * data) {
Serial.print("Sensor Data: ");
Serial.print(data[0]);
......@@ -63,6 +67,7 @@ long average(long a, long b) {
return (a + b) / 2;
}
// Compares the average of two values with a comparison value
bool check_against(long a, long b, long comp) {
long avg = average(a, b);
return abs(avg - comp) > 30;
......
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