Modifications

Sauter à la navigation Sauter à la recherche
Ligne 51 : Ligne 51 :  
Définition d'une fonction de rappel {{fname|toggle_relais()}} qui sera appelée lorsque le bouton 5 sera pressé.
 
Définition d'une fonction de rappel {{fname|toggle_relais()}} qui sera appelée lorsque le bouton 5 sera pressé.
   −
Les fonctions de rappel sont également dites "__callback__" en anglais.
+
Les fonctions de rappel sont également dites "''callback''" en anglais.
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Ligne 67 : Ligne 67 :  
         trellis.pixels[4] = RED  # Rouge
 
         trellis.pixels[4] = RED  # Rouge
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
Il faut maintenant associer le bouton 5 (index no 4) à la fonction de rappel.
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Ligne 74 : Ligne 76 :  
trellis.callbacks[4] = toggle_relay  
 
trellis.callbacks[4] = toggle_relay  
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
Le corps principal du script est exécute dans cette dernière section.
 +
 +
D'une façon générale, cela concerne le script utilisateur ainsi qu'un appel régulier à {{fname|trellis.sync()}} .
 +
 +
La méthode {{fname|sync()}} interroge le composant SeeSaw afin de détection l'éventualité d'un flan montant/descendant sur une entrée (l'un des "boutons Trellis").
 +
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
 
while True:
 
while True:
−
     # call the sync function call any triggered callbacks
+
     # Appel de sync() pour déclencher les fonctions de rappel
 
     trellis.sync()
 
     trellis.sync()
−
     # the trellis can only be read every 17 millisecons or so
+
     # Intervalle minimum de 17ms entre deux requêtes sur NeoTrellis.
 
     time.sleep(0.02)
 
     time.sleep(0.02)
 
</syntaxhighlight>
 
</syntaxhighlight>
    
{{Micropython-neotrellis-TRAILER}}
 
{{Micropython-neotrellis-TRAILER}}
32 920

modifications

Menu de navigation