⚲
Projet
Général
Profil
Connexion
S'enregistrer
Accueil
Projets
Aide
Recherche
:
Polytech Ge Sous Traitance
Tous les projets
Polytech Projets Ge
»
Polytech Ge Sous Traitance
Aperçu
Activité
Roadmap
Demandes
Gantt
Calendrier
Annonces
Documents
Wiki
Fichiers
Dépôt
Télécharger (1,01 ko)
Envoi et affichage cyclique
» slave.ino
afficher le 2éme caractere -
Anonyme, 19/11/2021 16:26
#include
<SoftwareSerial.h>
SoftwareSerial
mySerial
(
10
,
11
);
const
unsigned
int
MAX_MESSAGE_LENGTH
=
9
;
int
ledpin
[]
=
{
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
};
void
setup
()
{
Serial
.
begin
(
9600
);
mySerial
.
begin
(
9600
);
pinMode
(
2
,
OUTPUT
);
pinMode
(
3
,
OUTPUT
);
pinMode
(
4
,
OUTPUT
);
pinMode
(
5
,
OUTPUT
);
pinMode
(
6
,
OUTPUT
);
pinMode
(
7
,
OUTPUT
);
pinMode
(
8
,
OUTPUT
);
pinMode
(
9
,
OUTPUT
);
}
void
loop
()
{
while
(
mySerial
.
available
()
>
0
)
{
static
char
message
[
MAX_MESSAGE_LENGTH
];
static
unsigned
int
message_pos
=
0
;
char
inByte
=
mySerial
.
read
();
if
(
inByte
!=
'\n'
&&
(
message_pos
<
MAX_MESSAGE_LENGTH
-
1
)
)
{
message
[
message_pos
]
=
inByte
;
message_pos
++
;
}
else
{
message
[
message_pos
]
=
'\0'
;
mySerial
.
println
(
message
);
for
(
int
p
=
0
;
p
<
9
;
p
++
){
if
(
message
[
p
]
==
'1'
){
digitalWrite
(
ledpin
[
p
+
1
],
1
);
}
else
digitalWrite
(
ledpin
[
p
+
1
],
0
);
}
Serial
.
println
(
message
);
message_pos
=
0
;
}
}
}
« Précédent
1
2
Suivant »
(2-2/2)
Chargement...