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
9005cf80
Commit
9005cf80
authored
Oct 10, 2021
by
gujames
Browse files
Add light signal
parent
f18236cc
Changes
1
Hide whitespace changes
Inline
Side-by-side
10102021_main.ino
View file @
9005cf80
...
...
@@ -7,6 +7,8 @@ const int echo_pin_mid= 6;
const
int
trig_pin_right
=
5
;
const
int
echo_pin_right
=
4
;
const
int
trig_pin_light
=
2
;
struct
Ultrasoundreads
{
long
data1
,
data2
,
data3
;
}
ultrasound
;
...
...
@@ -27,6 +29,9 @@ void setup() {
pinMode
(
trig_pin_right
,
OUTPUT
);
pinMode
(
echo_pin_right
,
INPUT
);
// output a light signal when close by
pinMode
(
trig_pin_light
,
OUTPUT
);
for
(
int
i
=
0
;
i
<
19
;
++
i
)
{
data
[
i
]
=
{
0
,
0
,
0
};
}
...
...
@@ -110,7 +115,10 @@ double currspeed() {
void
loop
()
{
// reset light signal
digitalWrite
(
trig_pin_light
,
LOW
);
//array containg read ins from each US
long
reads
[
3
];
//read in from US sensors
...
...
@@ -124,11 +132,13 @@ void loop() {
bool
check_left
=
check_against
(
reads
[
1
],
reads
[
2
],
reads
[
0
]);
bool
check_mid
=
check_against
(
reads
[
0
],
reads
[
2
],
reads
[
1
]);
double
time
=
((
double
)
reads
[
1
])
/
currspeed
();
//
double time = ((double)reads[1]) / currspeed();
//time > 3 <- value can be set
if
((
check_right
||
check_left
||
check_mid
)
&&
time
>
3
)
{
if
((
check_right
||
check_left
||
check_mid
))
{
// output light signal
digitalWrite
(
trig_pin_light
,
HIGH
);
Serial
.
println
(
"There seems to be an object in the way..."
);
}
}
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