Nol.A SDK Library 26.11.2
For IoT System Software Development
Loading...
Searching...
No Matches
PCF8574 Class Reference

PCF8574 eight-pin quasi-bidirectional I2C expander. Call begin() first. Release input pins by writing 1; check lastError() after I/O. More...

#include <PCF8574.hpp>

Public Member Functions

 PCF8574 (TwoWire &wire, const uint8_t deviceAddress=0x20)
 Bind the bus and 7-bit device address (default 0x20).
bool begin (uint8_t value=PCF8574_INITIAL_VALUE)
 Probe the address and set the output latch to value. Initialize the I2C bus first.
bool isConnected ()
 Probe the device address and return whether it acknowledges.
bool setAddress (const uint8_t deviceAddress)
 Change the host-side 7-bit address and probe it; does not reprogram hardware. Refresh cached inputs/outputs with read8()/write8() after changing address.
uint8_t getAddress () const
 Return the configured host-side 7-bit address.
uint8_t read8 ()
 Read all eight input levels and cache them; inspect lastError() for I2C failure.
uint8_t read (const uint8_t pin)
 Read pin 0 through 7 as 0/1; invalid pins set PCF8574_PIN_ERROR.
uint8_t value () const
 Return the last cached input byte without bus access.
void write8 (const uint8_t value)
 Write and cache all eight output latch bits.
void write (const uint8_t pin, const uint8_t value)
 Update one output latch bit for pin 0 through 7.
uint8_t valueOut () const
 Return the cached output latch byte without bus access.
uint8_t readButton8 ()
 Read button inputs using the configured button mask.
uint8_t readButton8 (const uint8_t mask)
 Temporarily release the pins in mask, read inputs, and restore the output latch.
uint8_t readButton (const uint8_t pin)
 Release and read one button pin, then restore its output latch state.
void setButtonMask (const uint8_t mask)
 Cache the mask of pins released by the no-argument readButton8().
uint8_t getButtonMask () const
 Return the configured button mask.
void toggle (const uint8_t pin)
 Invert one cached output bit and write the latch; pin must be 0 through 7.
void toggleMask (const uint8_t mask=0xFF)
 Invert output latch bits selected by mask; default inverts all eight.
void shiftRight (const uint8_t n=1)
 Shift the output latch right by n bits, filling with zeros.
void shiftLeft (const uint8_t n=1)
 Shift the output latch left by n bits, filling with zeros.
void rotateRight (const uint8_t n=1)
 Rotate the eight output bits right by n positions.
void rotateLeft (const uint8_t n=1)
 Rotate the eight output bits left by n positions.
void reverse ()
 Reverse the order of the eight output bits and write the latch.
void select (const uint8_t pin)
 Set only the selected output pin high; pin must be 0 through 7.
void selectN (const uint8_t pin)
 Write the mask (2 << pin) - 1 for pin 0 through 7; other values write 0xFF.
void selectNone ()
 Drive all eight output latch bits low.
void selectAll ()
 Release all eight pins by writing all output latch bits high.
int lastError ()
 Return and clear the stored error (PCF8574_OK means no error).

Detailed Description

PCF8574 eight-pin quasi-bidirectional I2C expander. Call begin() first. Release input pins by writing 1; check lastError() after I/O.

Member Function Documentation

◆ begin()

bool PCF8574::begin ( uint8_t value = PCF8574_INITIAL_VALUE)

Probe the address and set the output latch to value. Initialize the I2C bus first.

Returns
True if the device acknowledges its address.

◆ getAddress()

uint8_t PCF8574::getAddress ( ) const
inline

Return the configured host-side 7-bit address.

74{ return _address; }

◆ getButtonMask()

uint8_t PCF8574::getButtonMask ( ) const
inline

Return the configured button mask.

124{ return _buttonMask; };

◆ readButton8()

uint8_t PCF8574::readButton8 ( )
inline

Read button inputs using the configured button mask.

108{ return PCF8574::readButton8(_buttonMask); }
uint8_t readButton8()
Read button inputs using the configured button mask.
Definition PCF8574.hpp:108

◆ selectAll()

void PCF8574::selectAll ( )
inline

Release all eight pins by writing all output latch bits high.

174{ write8(0xFF); };
void write8(const uint8_t value)
Write and cache all eight output latch bits.

◆ selectNone()

void PCF8574::selectNone ( )
inline

Drive all eight output latch bits low.

170{ write8(0x00); };

◆ setButtonMask()

void PCF8574::setButtonMask ( const uint8_t mask)
inline

Cache the mask of pins released by the no-argument readButton8().

120{ _buttonMask = mask; };

◆ value()

uint8_t PCF8574::value ( ) const
inline

Return the last cached input byte without bus access.

87{ return _dataIn; };

◆ valueOut()

uint8_t PCF8574::valueOut ( ) const
inline

Return the cached output latch byte without bus access.

101{ return _dataOut; }

The documentation for this class was generated from the following file: