Modifications

Sauter à la navigation Sauter à la recherche
586 octets ajoutés ,  2 mars 2015 à 11:55
aucun résumé de modification
Ligne 2 : Ligne 2 :     
== Introduction ==
 
== Introduction ==
{{bloc-etroit|text=The pyboard has 2 small switches, labelled USR and RST. The RST switch is a hard-reset switch, and if you press it then it restarts the pyboard from scratch, equivalent to turning the power off then back on.
+
{{bloc-etroit|text=Le pyboard dispose de 2 petits boutons, libellés USR et RST. Le bouton RST (''reset'') est un bouton de réinitialisation matérieln, s'il est prssé alors la carte pyboard redémarre entièrement (équivalent d'une mise hors tension suivit d'une remise sous tension).
   −
The USR switch is for general use, and is controlled via a Switch object. To make a switch object do:
+
Le bouton USR (''user'', soit utilisateur) est un bouton destiné à votre usage personnel. Il est contrôlé par l'intermédiaire de l'objet {{fname|Switch}}. Ecrivez le code suivant pour créer un objet Switch:
    
  <nowiki>>>> sw = pyb.Switch()</nowiki>
 
  <nowiki>>>> sw = pyb.Switch()</nowiki>
   −
Remember that you may need to type import pyb if you get an error that the name pyb does not exist.
+
Souvenez-vous qu'il faut taper {{fname|import pyb}} si vous obteniez une erreur vous informant que le nom {{fname|pyb}} n'existe pas.
   −
With the switch object you can get its status:
+
Grâce à l'objet ''switch'' vous pouvez obtenir le statut du bouton:
    
  <nowiki>>>> sw()
 
  <nowiki>>>> sw()
 
False</nowiki>
 
False</nowiki>
   −
This will print {{fname|False}} if the switch is not held, or {{fname|True}} if it is held. Try holding the USR switch down while running the above command.
+
Qui affiche {{fname|False}} si le bouton n'est pas pressé ou {{fname|True}} si le bouton est pressé. Essayez de maintenir le bouton enfoncé pendant l'exécution de la commande ci-dessus.
 
}}
 
}}
   Ligne 25 : Ligne 25 :  
{{bloc-etroit|text='''switch''' est un terme anglais signifiant "''bouton''" ou "''interrupteur''".
 
{{bloc-etroit|text='''switch''' est un terme anglais signifiant "''bouton''" ou "''interrupteur''".
   −
Nous disions donc que le '''switch''' is a very simple object, but it does have one advanced feature: the sw.callback() function. The callback function sets up something to run when the switch is pressed, and uses an interrupt. It’s probably best to start with an example before understanding how interrupts work. Try running the following at the prompt:
+
Nous disions donc que le '''switch''' est un objet vraiment très simple mais il dispose également d'une fonctionnalité avancée: la fonction {{fname|sw.callback()}}. La fonction callback permet de mettre en place quelque-chose à exécuter lorsque le bouton est pressé (et utilise une interruption). Le mieux, c'est de partir de l'exemple ci-dessus pour comprendre comment les interruptions fonctionnent.  
   −
<nowiki>>>> sw.callback(lambda:print('press!'))</nowiki>
+
Essayez d'exécuter le code suivant sur l'invite de commande:
   −
This tells the switch to print press! each time the switch is pressed down. Go ahead and try it: press the USR switch and watch the output on your PC. Note that this print will interrupt anything you are typing, and is an example of an interrupt routine running asynchronously.
+
<nowiki>>>> sw.callback(lambda:print('bouton enfonce!'))</nowiki>
   −
As another example try:
+
Qui informe le bouton qu'il doit imprimer un message 'bouton enfonce!' à chaque fois que le bouton est enfoncé. Faites un essai: pressez le bouton USR et regardez le message qui apparait sur la sortie de votre PC.
 +
 
 +
Notez que cet affichage interrompera tout ce que vous tapez. <font color="red">Ceci est un exemple de routine d'interruption qui s'exécute de façon asynchrone</font>.
 +
 
 +
Un autre exemple à essayer:
    
  <nowiki>>>> sw.callback(lambda:pyb.LED(1).toggle())</nowiki>
 
  <nowiki>>>> sw.callback(lambda:pyb.LED(1).toggle())</nowiki>
   −
This will toggle the red LED each time the switch is pressed. And it will even work while other code is running.
+
Dans cet exemple, le callback inverse (''toggle'') l'état de la LED rouge à chaque fois que le bouton est pressé. Et cela fonctionnera aussi pendant qu'un autre code s'exécute.
 +
 
 +
{{traduction}}
    
To disable the switch callback, pass None to the callback function:
 
To disable the switch callback, pass None to the callback function:
29 836

modifications

Menu de navigation