Modifications

Sauter à la navigation Sauter à la recherche
878 octets ajoutés ,  20 mai 2017 à 12:55
Ligne 77 : Ligne 77 :  
pfio.digital_write(0,1)
 
pfio.digital_write(0,1)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
=== 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:
 +
 +
<syntaxhighlight lang="python">
 +
from time import sleep
 +
import piface.pfio as pfio
 +
pfio.init()
 +
while(True):
 +
    pfio.digital_write(0,1) #turn on
 +
    sleep(1)
 +
    pfio.digital_write(0,0) #turn off
 +
    sleep(1)
 +
</syntaxhighlight>
 +
 +
=== Lire une entrée ===
 +
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''.
 +
 +
Start a new Python interpreter and type the following:
 +
 +
<syntaxhighlight lang="python">
 +
import piface.pfio as pfio
 +
pfio.init()
 +
pfio.digital_read(0)
 +
</syntaxhighlight>
 +
 +
Python prints ''0''.
 +
 +
Hold down the first switch, labelled ''S0'', and type {{fname|pfio.digital_read(0)}} again.
 +
 +
Python prints ''1''.
 +
    
{{PiFace2-Manuel-TRAILER}}
 
{{PiFace2-Manuel-TRAILER}}
29 917

modifications

Menu de navigation