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
89840b02
Commit
89840b02
authored
4 years ago
by
Antoine Rochebois
Browse files
Options
Downloads
Patches
Plain Diff
Update arduino/act1/act1.ino, public/activity_1/main-script.js files
parent
686a235a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#8
passed with stage
Stage:
in 33 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arduino/act1/act1.ino
+154
-0
154 additions, 0 deletions
arduino/act1/act1.ino
public/activity_1/main-script.js
+9
-0
9 additions, 0 deletions
public/activity_1/main-script.js
with
163 additions
and
0 deletions
arduino/act1/act1.ino
0 → 100644
+
154
−
0
View file @
89840b02
#include
<WebUSB.h>
#define IN1_1 2
#define IN2_1 3
#define IN3_1 4
#define IN4_1 5
#define IN1_2 10
#define IN2_2 16
#define IN3_2 14
#define IN4_2 15
#define REED_LH2 6
#define REED_LOX2 7
#define REED_RP1 8
#define REED_LOX1 9
String
currentCommand
=
""
;
unsigned
long
prevTime
=
0
;
WebUSB
WebUSBSerial
(
1
/* https:// */
,
"pole-jeune.pages.clubelek.fr/atelier_igb_apollo/activity_1/"
);
#define Serial WebUSBSerial
void
loadProp
(
String
tank
)
{
if
(
tank
==
"RP1"
)
{
digitalWrite
(
IN1_1
,
LOW
);
digitalWrite
(
IN2_1
,
HIGH
);
}
else
if
(
tank
==
"LH2"
)
{
digitalWrite
(
IN3_1
,
HIGH
);
digitalWrite
(
IN4_1
,
LOW
);
}
}
void
unloadProp
(
String
tank
)
{
if
(
tank
==
"RP1"
)
{
digitalWrite
(
IN1_1
,
HIGH
);
digitalWrite
(
IN2_1
,
LOW
);
}
else
if
(
tank
==
"LH2"
)
{
digitalWrite
(
IN3_1
,
LOW
);
digitalWrite
(
IN4_1
,
HIGH
);
}
}
void
stopLoading
(
String
tank
)
{
if
(
tank
==
"RP1"
)
{
digitalWrite
(
IN1_1
,
LOW
);
digitalWrite
(
IN2_1
,
LOW
);
}
else
if
(
tank
==
"LH2"
)
{
digitalWrite
(
IN3_1
,
LOW
);
digitalWrite
(
IN4_1
,
LOW
);
}
}
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
==
"LOAD"
)
{
loadProp
(
args
[
0
]);
}
else
if
(
id
==
"UNLOAD"
)
{
unloadProp
(
args
[
0
]);
}
else
if
(
id
==
"STOP"
)
{
stopLoading
(
args
[
0
]);
}
}
void
setup
()
{
while
(
!
Serial
)
{}
Serial
.
begin
(
9600
);
Serial
.
println
(
"Arduino connected and answering"
);
pinMode
(
REED_LH2
,
INPUT_PULLUP
);
pinMode
(
REED_LOX2
,
INPUT_PULLUP
);
pinMode
(
REED_RP1
,
INPUT_PULLUP
);
pinMode
(
REED_LOX1
,
INPUT_PULLUP
);
pinMode
(
IN1_1
,
OUTPUT
);
pinMode
(
IN2_1
,
OUTPUT
);
pinMode
(
IN3_1
,
OUTPUT
);
pinMode
(
IN4_1
,
OUTPUT
);
pinMode
(
IN1_2
,
OUTPUT
);
pinMode
(
IN2_2
,
OUTPUT
);
pinMode
(
IN3_2
,
OUTPUT
);
pinMode
(
IN4_2
,
OUTPUT
);
delay
(
1000
);
loadProp
(
"LH2"
);
loadProp
(
"RP1"
);
delay
(
3000
);
stopLoading
(
"LH2"
);
stopLoading
(
"RP1"
);
delay
(
1000
);
unloadProp
(
"LH2"
);
unloadProp
(
"RP1"
);
delay
(
3000
);
stopLoading
(
"LH2"
);
stopLoading
(
"RP1"
);
Serial
.
flush
();
}
void
loop
()
{
if
(
millis
()
-
prevTime
>=
1000
)
{
Serial
.
print
(
"REEDS_{LH2 :"
);
Serial
.
print
(
digitalRead
(
REED_LH2
));
Serial
.
print
(
", LOX2 :"
);
Serial
.
print
(
digitalRead
(
REED_LOX2
));
Serial
.
print
(
", RP1 :"
);
Serial
.
print
(
digitalRead
(
REED_RP1
));
Serial
.
print
(
", LOX1 :"
);
Serial
.
print
(
digitalRead
(
REED_LOX1
));
Serial
.
println
(
"}"
);
prevTime
=
millis
();
}
if
(
digitalRead
(
REED_LH2
))
{
stopLoading
(
"LH2"
);
}
if
(
digitalRead
(
REED_RP1
))
{
stopLoading
(
"RP1"
);
}
if
(
Serial
)
{
while
(
Serial
.
available
()
>
0
)
{
char
c
=
'0'
;
while
(
c
!=
';'
)
{
c
=
Serial
.
read
();
currentCommand
+=
c
;
delay
(
1
);
}
runCommand
(
currentCommand
);
currentCommand
=
""
;
}
Serial
.
flush
();
}
}
This diff is collapsed.
Click to expand it.
public/activity_1/main-script.js
+
9
−
0
View file @
89840b02
/* Insérer ici les fonctions spécifiques à cette activité. Elles peuvent marcher
/* Insérer ici les fonctions spécifiques à cette activité. Elles peuvent marcher
avec les fonctions et variables déjà définies dans 'activity_functions.js' du
avec les fonctions et variables déjà définies dans 'activity_functions.js' du
dossier 'res'.*/
dossier 'res'.*/
var
reedStatus
;
var
checkReedsInterval
=
setInterval
(
function
()
{
if
(
receivedMsg
.
startsWith
(
'
REEDS
'
))
{
reedsStatus
=
JSON
.
parse
(
receivedMsg
.
split
(
'
_
'
)[
1
])
console
.
log
(
reedsStatus
)
}
},
250
);
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