PCF8574¶
-
class
pcf8574.
PCF8574
(i2c, address, direction=None, state=None, inverted=None)¶ Class to control a PCF8574/A IC
Parameters: i2c (
I2C
) – I2C peripheraladdress (int) – Address of the PCF8574/A device
direction (str, optional) – Direction of pins
String representation of each pin (1 input / 0 output)
‘10100110’ = input, output, input, output*2, input*2, output
state (str, optional) – Initial digital state of pins (physical),
String representation of each pin (1 on / 0 off for output, 1 for input)
‘10101111’ = input, off, input, off, on, input*2, on
inverted (str, optional) – Inverted pins
String representation of each pin (1 inverted / 0 non inverted)
‘11100011’ = inverted*3, non*3, inverted*2
Variables: - interrupt (int) – counter for interruption
- changed_pins (bytearray) – bytearray of [pin/value] * 8 where pin is set to 1 when changed and value is the new value of the pin.
-
direction
(pin)¶ Return the direction of a pin
Parameters: pin (int) – pin 0-7 Returns: 1 for input, 0 for output Return type: int
-
disable_int
()¶ Disable interrupt
-
enable_int
(pin)¶ Enable input interrupt
To get the changed pins, use the attribut changed_pins
Parameters: pin (int) – interrupt pin
-
input_pin
(pin, invert=False)¶ Set pin(s) as input
Parameters: pin (int or list) – pin 0-7
invert (bool, optional) – True inverted pin, False non inverted pin. Defaults to False.
If a list of pins is given, invert applies to all pins
-
invert_pin
(pin, invert=False)¶ Set a pin has inverted or not
Previous state is kept
Parameters: pin (int or list) – pin 0-7
invert (bool, optional) – True inverted pin, False non inverted pin. Defaults to False.
If a list of pins is given, invert applies to all pins
-
inverted
(pin)¶ Return the inverted state of a pin
Parameters: pin (int) – pin 0-7 Returns: 1 for inverted, 0 for non inverted Return type: int
-
output_pin
(pin, invert=False)¶ Set pin(s) as output
Parameters: pin (int or list) – pin 0-7
invert (bool, optional) – True inverted pin, False non inverted pin. Defaults to False.
If a list of pins is given, invert applies to all pins
-
read_pin
(pin)¶ Read value of a pin
Parameters: pin (int) – pin 0-7 Returns: The pin value 0 or 1 Return type: int
-
reset_int
()¶ Reset interrupt
Use this method after using the interrupt
-
write_pin
(pin, value)¶ Write value to an output pin
Parameters: - pin (int) – pin 0-7
- value (bool) – value to write