Modifications

Sauter à la navigation Sauter à la recherche
1 165 octets ajoutés ,  13 février 2016 à 06:48
Ligne 39 : Ligne 39 :     
Votre script Python peut également contenir la définition de fonctions et d'objets. Le corps de votre programme pourra alors y faire appel.
 
Votre script Python peut également contenir la définition de fonctions et d'objets. Le corps de votre programme pourra alors y faire appel.
 +
 +
=== Bonne pratiques ===
 +
Idéalement:
 +
# Déclarer les constantes en début de script
 +
# Initialiser les broches d'entrées/sortie en début de script (aussi tôt que possible)
 +
# Définir les fonctions et objets
 +
# Corps principal de votre programme
 +
# dés-initialisation (si applicable).
 +
 +
Voici un tout petit exemple qui illustre ces recommandation. 
 +
 +
<nowiki># --- DEFINITION DES CONSTANTES ---
 +
RED_PIN = pyb.Pin.board.Y10    # Led rouge
 +
GREEN_PIN = pyb.Pin.board.Y11  # Led verte
 +
BLUE_PIN = pyb.Pin.board.Y12  # Led bleue
 +
 +
# --- INITIALISATION DES BROCHES ---
 +
pRed = pyb.Pin( RED_PIN, pyb.Pin.OUT_PP )
 +
pGreen = pyb.Pin( GREEN_PIN, pyb.Pin.OUT_PP )
 +
pBlue = pyb.Pin( BLUE_PIN, pyb.Pin.OUT_PP )
 +
 +
# --- CORPS DU PROGRAMME ----
 +
 +
# Allumer la led ROUGE
 +
pRed.low()
 +
pGreen.high()
 +
pBlue.high()
 +
 +
# Attendre 1 secondes
 +
pyb.delay( 1000 )
 +
 +
# Allumer la led BLEUE
 +
pRed.high()
 +
pGreen.high()
 +
pBlue.low()
 +
 +
# Attendre 1 secondes
 +
pyb.delay( 1000 )   
 +
 +
# Allumer la led VERTE
 +
pRed.high()
 +
pGreen.low()
 +
pBlue.high()
 +
 +
# Attendre 1 secondes
 +
pyb.delay( 1000 )   
 +
 +
# --- FIN DE PROGRAMME ---
 +
 +
# Tout en noir (toutes les LEDs éteintes)
 +
pRed.high()
 +
pGreen.high()
 +
pBlue.high()
 +
</nowiki>
    
== Syntaxe ==
 
== Syntaxe ==
29 917

modifications

Menu de navigation