Modifications

Sauter à la navigation Sauter à la recherche
1 325 octets ajoutés ,  20 mai 2017 à 20:25
aucun résumé de modification
Ligne 3 : Ligne 3 :  
{{traduction}}
 
{{traduction}}
 
== Premiers pas avec Python ==
 
== Premiers pas avec Python ==
−
PiFace Digital 2 can be controlled easily using Python. First open a terminal window and start the Python interpreter by typing:
+
PiFace Digital 2 peut être contrôlé facilement en utilisant Python. Pour commencer, ouvrez un terminal (ligne de commande) et démarrez un interpréteur en saisissant la commande suivante:
    
  python3
 
  python3
   −
To use PiFace Digital 2 from Python you must import the pifacedigitalio module:
+
{{ambox|text=Vous pouvez également utiliser l'éditeur "Idle" disponible dans l'environnement graphique}}
 +
 
 +
Pour utiliser le PiFace Digital 2 depuis Python, il faut importer le module {{fname|pifacedigitalio}} :
    
  import pifacedigitalio
 
  import pifacedigitalio
   −
Before use, the board must be initialised with a call to:
+
Avant d'utiliser la carte PiFace, il faut initialiser la bibliothèque en faisant l'appel suivant:
    
  pifacedigitalio.init()
 
  pifacedigitalio.init()
   −
Use the digital_read function to see if a button is pressed or not:
+
Si vous désirez savoir si un bouton est enfoncé ou non, il faut utiliser la fonction {{fname|digital_read}} :
   −
  pifacedigitalio.digital_read(pin_number)
+
  pifacedigitalio.digital_read( numero_de_broche )
   −
This function returns ''1'' if the input numbered ''pin_number'' is connected to ground or else ''0''.
+
La fonction retourne ''1'' si l'entrée indiquée dans ''numero_de_broche'' si le bouton est enfoncé ou l'entrée est connecté sur la masse (GND). Sinon la fonction retourne ''0''.
   −
Set the output numbered ''pin_number'' to state ''0'' or ''1''. State ''1'' turns the LED on and enables to open-collector to sink current.
+
Si vous désirez contrôler une sortie, il faut utiliser la fonction {{fname|digital_write}} :
 +
 +
pifacedigitalio.digital_write( numero_de_broche, etat )
   −
pifacedigitalio.digital_write(pin_number, state)
+
La fonction permet de fixer l'état de la broche ''numero_de_broche'' sur l'état '''0''' (inactif) ou '''1''' (actif). L'état ''1'' active le collecteur ouvert (qui laisse passer le courant) et la LED correspondante.
    
== Les pas suivants ==
 
== Les pas suivants ==
−
A more powerful and expressive way of controlling PiFace Digital 2 is using the PiFaceDigital object.  
+
Une façon plus puissante et plus explicite de contrôler le PiFace est de passer par un objet {{fname|PiFaceDigital}}.
−
This will give you access to all PiFaceTM Digital 2’s the features (including pull-ups and input/output ports).
+
 +
En créant un objet de type {{fname|PiFaceDigital}}, vous aurez accès à toutes les fonctionnalités du PiFace (incluant l'activation des pull-ups, l'input_port et output_port).
   −
Start the Python interpreter with:
+
Démarrer un interpréteur python à l'aide de la commande:
    
  python3
 
  python3
   −
Then instantiate the ''PiFaceDigital'' object like this:
+
Instanciez ensuite un objet ''PiFaceDigital'' à l'aide de l'instruction suivante:
 
   
 
   
 
  import pifacedigitalio
 
  import pifacedigitalio
Ligne 39 : Ligne 44 :     
=== Sorties ===
 
=== Sorties ===
−
Set the first output pin to ''1'' (the on state):
+
Pour fixer la première sortie (celle qui porte le numéro 0) sur l'état ''1'' (pour activer la sortie):
    
  pfd.output_pins[0].value = 1
 
  pfd.output_pins[0].value = 1
   −
Notice how the first relay clicks as it activates. Output pin ''0'' controls the first relay. You can
+
Notez le petit cliquetis du relais lorsqu'il s'active. La broche de sortie ''0'' contrôle également le premier relais.  
−
turn the output pin (and the relay) off by setting it to ''0'':
+
 
 +
Vous pouvez également désactiver la sortie numéro 0 (et le relais) en fixant la valeur de la sortie à ''0'':
    
  pfd.output_pins[0].value = 0
 
  pfd.output_pins[0].value = 0
    
=== Entrées ===
 
=== Entrées ===
−
You can read the value of an input pin like this:
+
Vous pouvez lire la valeur d'une entrée à l'aide de l'instruction suivante:
    
  pfd.input_pins[1].value
 
  pfd.input_pins[1].value
   −
Try running the above command with the second switch pressed and then again with it unpressed and you should get different results.
+
Essayez d'exécuter l'instruction ci-dessus en pressant le second bouton (qui porte le numéro 1) PUIS exécutée une seconde fois sans presser le bouton.
 +
 
 +
Vous devriez voir deux résultats différents.
    
=== input_port et output_port ===
 
=== input_port et output_port ===
−
You can read the whole input port by reading the value of the input_port attribute:
+
Vous pouvez lire toutes les entrées en une seule opération en utilisant l'attribut {{fname|input_port}} :
 
   
 
   
 
  pfd.input_port.value
 
  pfd.input_port.value
   −
Or set the outputs for the whole port by setting the value of the output_port attribute:
+
Input port affiche une valeur numérique qui, une fois exprimée en valeur binaire, indique l'état de chaque entrée.
 +
 
 +
Il est également possible de contrôler toutes les sorties en une opération en manipulant l'attribut {{fname|output_port}} :
    
  pfd.output_port.value = 0xAA
 
  pfd.output_port.value = 0xAA
Ligne 66 : Ligne 76 :  
== Exemples python ==
 
== Exemples python ==
   −
=== Activer un relai ===
+
=== Activer un relais ===
   −
The relays on PiFaceTM Digital 2 are connected to the first two outputs, so they can be controlled using the digital_write function.
+
Les relais du PiFace Digital sont respectivement connecté sur les deux premières entrées 0 et 1. Vous pouvez donc contrôler ces deux relais à l'aide de la fonction {{fname|digital_write()}}.
    
Start a new Python interpreter and type the following:
 
Start a new Python interpreter and type the following:
Ligne 75 : Ligne 85 :  
import piface.pfio as pfio
 
import piface.pfio as pfio
 
pfio.init()
 
pfio.init()
 +
# mettre la sortie 0 a l etat 1 (activer)
 
pfio.digital_write(0,1)
 
pfio.digital_write(0,1)
 
</syntaxhighlight>
 
</syntaxhighlight>
    
=== Clignoter une LED ====
 
=== Clignoter une LED ====
−
A program to flash an LED must repeatedly turn an output on, wait for a period and then turn it off again. It is shown below:
+
Un programme qui fait clignoter une LED doit l'allumer et l'éteindre de façon répétitive (avec un délai entre chaque activation/désactivation).  
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Ligne 86 : Ligne 97 :  
pfio.init()
 
pfio.init()
 
while(True):
 
while(True):
−
     pfio.digital_write(0,1) #turn on
+
    # activer la sortie 0 = allumer la LED
 +
     pfio.digital_write(0,1)
 +
    # Attendre une seconde
 
     sleep(1)
 
     sleep(1)
−
     pfio.digital_write(0,0) #turn off
+
    # désactiver la sortie 0 = eteindre la LED
 +
     pfio.digital_write(0,0)
 
     sleep(1)
 
     sleep(1)
 
</syntaxhighlight>
 
</syntaxhighlight>
32 920

modifications

Menu de navigation