⚲
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 (761 octets)
Feature #13387
» Arduino_scanner_code.ino
Code scannant la présence d'un slave I²C -
Anonyme, 10/11/2021 14:12
#include
<Wire.h>
void
setup
()
{
Wire
.
begin
();
Serial
.
begin
(
9600
);
Serial
.
println
(
"
\n
I2C Scanner"
);
}
void
loop
()
{
byte
error
,
address
;
int
Devices
;
Serial
.
println
(
"Scanning..."
);
Devices
=
0
;
for
(
address
=
1
;
address
<
127
;
address
++
)
{
Wire
.
beginTransmission
(
address
);
error
=
Wire
.
endTransmission
();
if
(
error
==
0
)
{
Serial
.
print
(
"I2C device found at address 0x"
);
if
(
address
<
16
)
Serial
.
print
(
"0"
);
Serial
.
print
(
address
,
HEX
);
Serial
.
println
(
" !"
);
Devices
++
;
}
else
if
(
error
==
4
)
{
Serial
.
print
(
"Unknown error at address 0x"
);
if
(
address
<
16
)
Serial
.
print
(
"0"
);
Serial
.
println
(
address
,
HEX
);
}
}
if
(
Devices
==
0
)
Serial
.
println
(
"No I2C devices found
\n
"
);
else
Serial
.
println
(
"done
\n
"
);
delay
(
1000
);
}
« Précédent
1
2
3
4
Suivant »
(3-3/4)
Chargement...