To read the state of an input use the {{fname|pfio.digital_read(pin)}} function. If a button is pressed the function returns a ''1'', otherwise it returns a ''0''.
+
Il faut utiliser la fonction {{fname|pfio.digital_read(pin)}} pour lire l'état d'une entrée. La fonction retourne ''1'' si le bouton est pressé (ou entrée activée) sinon elle retourne ''0'' .
−
Start a new Python interpreter and type the following:
+
Démarrez un nouvel interpréteur Python et saisissez les instructions suivantes:
<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
import piface.pfio as pfio
import piface.pfio as pfio
pfio.init()
pfio.init()
+
# lecture de l entree 0 (correspond au premier bouton)
pfio.digital_read(0)
pfio.digital_read(0)
</syntaxhighlight>
</syntaxhighlight>
−
Python prints ''0''.
+
Python affiche ''0''.
−
Hold down the first switch, labelled ''S0'', and type {{fname|pfio.digital_read(0)}} again.
+
Maintenez le premier switch enfoncé (celui portant le libellé ''S0'') et saisissez une nouvelle fois la commande {{fname|pfio.digital_read(0)}} .