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
6413864a
Commit
6413864a
authored
Jan 26, 2021
by
Brandon Fan
Browse files
add a virtual delay to the main.ino (needs testing)
parent
c65f3408
Changes
1
Hide whitespace changes
Inline
Side-by-side
main/main.ino
View file @
6413864a
...
...
@@ -57,14 +57,23 @@ void loop() {
}
void
turnOnLight
(
int
trigPin
,
int
time1
,
int
time2
)
{
VirtualDelay
delay1
;
VirtualDelay
delay2
;
delay1
.
start
(
time1
);
if
(
delay1
.
elapsed
())
{
digitalWrite
(
trigPin
,
HIGH
);
delay2
.
start
(
time2
);
if
(
delay2
.
elapsed
())
{
digitalWrite
(
trigPin
,
LOW
);
}
}
}
void
usSensor
(
int
trigPin
,
int
echoPin
,
int
sensorNum
)
{
int
ledPin
=
0
;
digitalWrite
(
trigPin
,
LOW
);
delay
(
2
);
digitalWrite
(
trigPin
,
HIGH
);
delay
(
100
);
digitalWrite
(
trigPin
,
LOW
);
turnOnLight
(
trigPin
,
2
,
100
);
duration
=
pulseIn
(
echoPin
,
HIGH
);
int
distance
=
duration
*
(
0.034
/
2
);
...
...
@@ -91,9 +100,7 @@ void usSensor(int trigPin, int echoPin, int sensorNum) {
if
(
distance
<
30
)
{
digitalWrite
(
ledPin
,
HIGH
);
delay
(
distance
*
15
);
digitalWrite
(
ledPin
,
LOW
);
turnOnLight
(
ledPin
,
distance
*
15
,
0
);
//delay(distance * 15);
Serial
.
print
(
"Obstacle detected: Sensor "
);
...
...
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