1 556 octets ajoutés
, 20 mai 2017 à 11:57
{{PiFace2-Manuel-NAV}}
{{traduction}}
== 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:
python3
To use PiFace Digital 2 from Python you must import the pifacedigitalio module:
import pifacedigitalio
Before use, the board must be initialised with a call to:
pifacedigitalio.init()
Use the digital_read function to see if a button is pressed or not:
pifacedigitalio.digital_read(pin_number)
This function returns ''1'' if the input numbered ''pin_number'' is connected to ground or else ''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.
pifacedigitalio.digital_write(pin_number, state)
== Les pas suivants ==
A more powerful and expressive way of controlling PiFace Digital 2 is using the PiFaceDigital object.
This will give you access to all PiFaceTM Digital 2’s the features (including pull-ups and input/output ports).
Start the Python interpreter with:
python3
Then instantiate the ''PiFaceDigital'' object like this:
import pifacedigitalio
pfd = pifacedigitalio.PiFaceDigital()
== Sorties ==
Set the first output pin to ''1'' (the on state):
pfd.output_pins[0].value = 1
Notice how the first relay clicks as it activates. Output pin ''0'' controls the first relay. You can
turn the output pin (and the relay) off by setting it to ''0'':
pfd.output_pins[0].value = 0
== Entrées ==
{{PiFace2-Manuel-TRAILER}}