Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Atelier IGB Apollo
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pôle Jeune
Atelier IGB Apollo
Commits
4cf807bc
Commit
4cf807bc
authored
4 years ago
by
antoinekia
Browse files
Options
Downloads
Patches
Plain Diff
act1
parent
7a396c8c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
arduino/act1/act1.ino
+86
-0
86 additions, 0 deletions
arduino/act1/act1.ino
with
86 additions
and
0 deletions
arduino/act1/act1.ino
0 → 100644
+
86
−
0
View file @
4cf807bc
#include
<WebUSB.h>
/**
Creating an instance of WebUSBSerial will add an additional USB interface to
the device that is marked as vendor-specific (rather than USB CDC-ACM) and
is therefore accessible to the browser.
The URL here provides a hint to the browser about what page the user should
navigate to to interact with the device.
*/
WebUSB
WebUSBSerial
(
1
/* https:// */
,
"apollo.antoine-rcbs.ovh/activity_1"
);
DFMiniMp3
<
HardwareSerial
,
Mp3Notify
>
mp3
(
Serial1
);
#define Serial WebUSBSerial
#define RING_PIN 2
String
currentCommand
=
""
;
void
setup
()
{
while
(
!
Serial
)
{
;
}
Serial
.
begin
(
9600
);
Serial
.
println
(
"Arduino connected and answering"
);
delay
(
1000
);
Serial
.
flush
();
}
void
loop
()
{
if
(
Serial
)
{
while
(
Serial
.
available
()
>
0
)
{
char
c
=
'0'
;
while
(
c
!=
';'
)
{
c
=
Serial
.
read
();
currentCommand
+=
c
;
delay
(
1
);
}
runCommand
(
currentCommand
);
currentCommand
=
""
;
}
Serial
.
flush
();
}
}
void
runCommand
(
String
command
)
{
//Décomposition de la commande en ID + arguments
int
curIndex
=
command
.
indexOf
(
'_'
);
String
id
=
command
.
substring
(
0
,
curIndex
);
Serial
.
print
(
id
);
String
args
[
5
]
=
{
"0"
,
"0"
,
"0"
,
"0"
,
"0"
};
//Max 5 args
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
int
nextIndex
=
command
.
indexOf
(
'_'
,
curIndex
+
1
);
args
[
i
]
=
command
.
substring
(
curIndex
+
1
,
nextIndex
);
Serial
.
print
(
args
[
i
]);
curIndex
=
nextIndex
;
if
(
args
[
i
].
endsWith
(
";"
))
{
args
[
i
].
remove
(
args
[
i
].
indexOf
(
';'
));
break
;
}
}
//Lancement des diverses commandes
if
(
id
==
"IO"
)
{
turnIO
(
args
[
0
].
toInt
(),
args
[
1
].
toInt
());
}
else
if
(
id
==
"DELAY"
)
{
waitForUnlock
(
args
[
0
].
toInt
());
}
}
/* FONCTIONS METIER */
void
turnIO
(
int
pin
,
boolean
val
)
{
digitalWrite
(
pin
,
val
);
}
void
waitForUnlock
(
int
delayMs
)
{
delay
(
delayMs
);
Serial
.
println
(
"UNLOCK;"
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment