Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
MEND
electrical
Commits
34661c23
Commit
34661c23
authored
Mar 16, 2021
by
Brandon Fan
💬
Browse files
add documentation
parent
e4548f47
Changes
1
Hide whitespace changes
Inline
Side-by-side
Main_working/Main_working.ino
View file @
34661c23
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment