PiFace2-Manuel-Python

De MCHobby - Wiki
Révision datée du 20 mai 2017 à 11:57 par Admin (discussion | contributions) (Page créée avec « {{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 Py... »)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)
Sauter à la navigation Sauter à la recherche


MCHobby investit du temps et de l'argent dans la réalisation de traduction et/ou documentation. C'est un travail long et fastidieux réalisé dans l'esprit Open-Source... donc gratuit et librement accessible.
SI vous aimez nos traductions et documentations ALORS aidez nous à en produire plus en achetant vos produits chez MCHobby.

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


Traduction basée sur le document Technical DataSheet produit par Farnell

Toute référence, mention ou extrait de cette traduction doit être explicitement accompagné du texte suivant : «  Traduction par MCHobby (www.MCHobby.be) - Vente de kit et composants » avec un lien vers la source (donc cette page) et ce quelque soit le média utilisé.

L'utilisation commercial de la traduction (texte) et/ou réalisation, même partielle, pourrait être soumis à redevance. Dans tous les cas de figures, vous devez également obtenir l'accord du(des) détenteur initial des droits. Celui de MC Hobby s'arrêtant au travail de traduction proprement dit.