fusion_hat.pin Modul

Pin-Manipulationsklasse

Beispiel

Einfaches Beispiel mit Auto-Modus

>>> from fusion_hat.pin import Pin
>>> pin = Pin(17)
>>> pin.value() # read the pin input value
0
>>> pin.value(1) # output pin value to high
1

Ausgabemodus

>>> from fusion_hat.pin import Pin
>>> pin = Pin(17, mode=Pin.OUT)
>>> pin.value(1) # output high
1
>>> pin.value(0) # output low
0
>>> pin.value() # read current value, not as input
0
>>> pin.on() # output high
1
>>> pin.off() # output low
0

Eingabemodus

>>> pin = Pin(17, mode=Pin.IN, pull=Pin.PULL_UP)
>>> pin.value() # read the pin input value
0

Aktiver Zustand. Wenn Ihre LED aktiv LOW ist, können Sie active_state setzen, um die Verwendung zu vereinfachen.

>>> led = Pin(17, mode=Pin.OUT, active_state=Pin.ACTIVE_LOW)
>>> led.on() # output low but turn on the LED
0
>>> led.off() # output high but turn off the LED
1
>>> led.value() # read current value, not as input
1
>>> led.raw(1) # You can still set the raw value
1

Wenn auch Ihre Taste aktiv LOW ist, können Sie active_state auf Pin.ACTIVE_LOW setzen. Sie können dasselbe tun.

>>> button = Pin(17, mode=Pin.IN, pull=Pin.PULL_UP, active_state=Pin.ACTIVE_LOW)
>>> button.value() # read's pin low but return 1 as pressed
1
>>> button.raw() # You can still read the raw value
0

Sie können auch Interrupts für den aktivierten oder deaktivierten Zustand setzen.

>>> button = Pin(17, mode=Pin.IN, pull=Pin.PULL_UP, active_state=Pin.ACTIVE_LOW, bouncetime=0.02)
>>> def on_press(pin: Pin) -> None:
...     print("press")
>>> def on_release(pin: Pin) -> None:
...     print("release")
>>> button.when_activated = on_press
>>> button.when_deactivated = on_release
pressed
release
class fusion_hat.pin.Mode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[Quellcode]

Basisklassen: Enum

Pin-Richtung

AUTO = None

Pin-Richtung Auto

IN

Pin-Richtung Eingang

OUT

Pin-Richtung Ausgang

class fusion_hat.pin.Pull(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[Quellcode]

Basisklassen: Enum

Pin Pull-Up / Pull-Down

UP

Interner Pull-Up des Pins

DOWN

Interner Pull-Down des Pins

NONE

Kein interner Pull-Widerstandstand des Pins

class fusion_hat.pin.Active(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[Quellcode]

Basisklassen: Enum

Pin-Aktivzustand

HIGH = True

Pin-Aktivzustand High

LOW = False

Pin-Aktivzustand Low

class fusion_hat.pin.Trigger(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[Quellcode]

Basisklassen: Enum

Pin-Interrupt

FALLING

Pin-Interrupt fallend

RISING

Pin-Interrupt steigend

BOTH

Pin-Interrupt sowohl steigend als auch fallend

class fusion_hat.pin.Pin(pin: int, *args, mode: Mode = Mode.AUTO, pull: Pull = RPi.GPIO.PUD_OFF, active_state: Active = Active.HIGH, bounce_time: float = 0.02, **kwargs)[Quellcode]

Basisklassen: _Base

Pin-Manipulationsklasse

Eine Pin-Wrapper-Klasse für RPi.GPIO. Auf dem Pi 5 müssen Sie rpi.lgpio statt RPi.GPIO installieren.

Parameter:
  • pin (int) – Pin-Nummer des Raspberry Pi

  • mode (Mode, optional) – Pin-Modus ( IN / OUT / AUTO ). Standard ist Mode.AUTO.

  • pull (Pull, optional) – Pin-Pull ( Pull.UP / Pull.DOWN / Pull.NONE ). Standard ist Pull.NONE.

  • active_state (Active, optional) – Aktiver Zustand des Pins. Wenn True, ist der Software-Pin HIGH, wenn der Hardware-Pin HIGH ist. Wenn False, wird die Eingangspolarität invertiert. Standard ist Active.HIGH.

  • bounce_time (float, optional) – Entprellzeit des Pin-Interrupts in Sekunden. Standard ist 0.02.

  • *args – Zusätzliche Argumente für fusion_hat._base._Base

  • **kwargs – Zusätzliche Schlüsselwortargumente für fusion_hat._base._Base

OUT

Pin-Modus Ausgang

IN

Pin-Modus Eingang

AUTO = None

Pin-Modus Auto

PULL_UP

Interner Pull-Up des Pins

PULL_DOWN

Interner Pull-Down des Pins

PULL_NONE

Kein interner Pull-Widerstandstand des Pins

ACTIVE_HIGH = True

Pin-Aktivzustand High

ACTIVE_LOW = False

Pin-Aktivzustand Low

IRQ_FALLING

Pin-Interrupt fallend

IRQ_RISING

Pin-Interrupt steigend

IRQ_RISING_FALLING

Pin-Interrupt sowohl steigend als auch fallend

close() None[Quellcode]

Den Pin schließen

deinit() None[Quellcode]

Den Pin deinitialisieren

setup(mode: Mode = Mode.AUTO, pull: Pull = RPi.GPIO.PUD_OFF, active_state: Active = Active.HIGH, bounce_time: float = 0.02) None[Quellcode]

Den Pin einrichten

Parameter:
  • mode (Mode, optional) – Pin-Modus ( IN / OUT / AUTO ). Standard ist Mode.AUTO.

  • pull (Pull, optional) – Pin-Pull ( Pull.UP / Pull.DOWN / Pull.NONE ). Standard ist Pull.NONE.

  • active_state (Active, optional) – Aktiver Zustand des Pins. Wenn True, ist der Software-Pin HIGH, wenn der Hardware-Pin HIGH ist. Wenn False, wird die Eingangspolarität invertiert. Standard ist Active.HIGH.

  • bounce_time (float, optional) – Entprellzeit des Pin-Interrupts in Sekunden. Standard ist 0.02.

__call__(value: [<class 'bool'>, <class 'int'>] = None) int[Quellcode]

Pin-Wert setzen oder abrufen

Parameter:

value (bool/int, optional) – Pin-Wert, leer lassen, um den Wert ( 0 / 1 ) zu erhalten. Standard ist None.

Rückgabe:

Pin-Wert ( 0 / 1 )

Rückgabetyp:

int

raw(value: [<class 'bool'>, <class 'int'>] = None) int[Quellcode]

Rohwert des Pins setzen oder abrufen

Parameter:

value (bool/int, optional) – Pin-Wert, leer lassen, um den Wert ( 0 / 1 ) zu erhalten. Standard ist None.

Rückgabe:

Pin-Wert ( 0 / 1 )

Rückgabetyp:

int

Verursacht:

ValueError – wenn der Pin-Modus IN ist

value(value: [<class 'bool'>, <class 'int'>] = None) int[Quellcode]

Pin-Wert setzen oder abrufen

Parameter:

value (bool/int, optional) – Pin-Wert, leer lassen, um den Wert ( 0 / 1 ) zu erhalten. Standard ist None.

Rückgabe:

Pin-Wert ( 0 / 1 )

Rückgabetyp:

int

Verursacht:

ValueError – wenn der Pin-Modus IN ist

on() int[Quellcode]

Pin auf Ein ( High ) setzen

Rückgabe:

Pin-Wert ( 1 )

Rückgabetyp:

int

off() int[Quellcode]

Pin auf Aus ( Low ) setzen

Rückgabe:

Pin-Wert ( 0 )

Rückgabetyp:

int

high() int[Quellcode]

Pin auf High ( 1 ) setzen

Rückgabe:

Pin-Wert ( 1 )

Rückgabetyp:

int

low() int[Quellcode]

Pin auf Low ( 0 ) setzen

Rückgabe:

Pin-Wert ( 0 )

Rückgabetyp:

int

irq(handler: Callable[[], None], trigger: Trigger = RPi.GPIO.BOTH) None[Quellcode]

Den Pin-Interrupt setzen

Parameter:
  • handler (Callable[[], None]) – Callback-Funktion des Interrupt-Handlers

  • trigger (Trigger, optional) – Interrupt-Trigger ( RISING, FALLING, RISING_FALLING ). Standard ist Trigger.BOTH.

Verursacht:

ValueError – wenn der Trigger nicht gültig ist

init_irq() None[Quellcode]

Den Pin-Interrupt initialisieren

irq_handler(channel: int) None[Quellcode]

Den Pin-Interrupt verarbeiten

Parameter:

channel (int) – Pin-Nummer

property when_activated: Callable[[], None]

Den Handler für Gedrückt abrufen

Rückgabe:

Gedrückt-Handler

Rückgabetyp:

Callable[[], None]

property when_deactivated: Callable[[], None]

Den Handler für Losgelassen abrufen

Rückgabe:

Losgelassen-Handler

Rückgabetyp:

Callable[[], None]