⚲
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 (923 octets)
Support #14574
» servo.ino
Papa Abdoulaye NDIAYE
, 16/12/2022 15:15
#include
<Servo.h>
int
pos
;
//variable qui va recueillir la position du servo
int
interruptPin
=
2
;
// numero du pin d'interruption voulu
Servo
myservo
;
void
setup
()
{
myservo
.
attach
(
9
);
// le servo est attache au pin 9
pinMode
(
interruptPin
,
INPUT
);
// Définir la broche d'interruption comme une broche d'entrée
attachInterrupt
(
digitalPinToInterrupt
(
interruptPin
),
servo
,
CHANGE
);
// interruption du pin 2 est attachée a la fonction servo
}
void
loop
()
{
pos
=
myservo
.
read
();
// On lit la valeur actuel du servo
}
void
servo
()
{
//on fait une rotation de 90 degres pour appuyer sur le bouton switch
for
(
int
position
=
pos
;
position
<=
90
;
position
++
)
{
myservo
.
write
(
position
);
delay
(
15
);
}
delay
(
800
);
// on retourne à la position 0°
for
(
int
position
=
90
;
position
>=
0
;
position
--
)
{
myservo
.
write
(
position
);
delay
(
15
);
}
}
(1-1/1)
Chargement...