SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
pca9570_expander.ino
Go to the documentation of this file.
1
30#include <IoExpanderDrv.hpp>
31
32#ifndef SENSOR_SDA
33#define SENSOR_SDA 17
34#endif
35
36#ifndef SENSOR_SCL
37#define SENSOR_SCL 18
38#endif
39
41
42void setup()
43{
44 Serial.begin(115200);
45
46 if (!expander.begin(Wire, PCA9570_SLAVE_ADDRESS, SENSOR_SDA, SENSOR_SCL)) {
47 while (1) {
48 Serial.println("Failed to find PCA9570 - check your wiring!");
49 delay(1000);
50 }
51 }
52
53 // Since PCA9570 pins are fixed as outputs, this call merely updates the software pin mode
54 // cache and does not perform any actual hardware configuration.
56}
57
58void loop()
59{
60 // Set all pins to 1
61 Serial.println("Set port HIGH");
62 expander.digitalWritePort(0x0F, HIGH);
63 delay(1000);
64
65 Serial.println("Set port LOW");
66 // Set all pins to 0
67 expander.digitalWritePort(0x00, LOW);
68 delay(1000);
69
70 Serial.println("digitalWrite 0");
71 expander.digitalWrite(0, HIGH);
72 delay(1000);
73
74 Serial.println("digitalToggle 0");
76 delay(1000);
77}
@license MIT License
bool begin(SensorCommCustom::CustomCallback callback, uint8_t addr)
Initialize the sensor using custom callback interface.
void digitalToggle(uint8_t pin)
Toggle the state of an output pin.
void digitalWrite(uint8_t pin, bool value)
Write a digital value to an output pin.
void configPins(uint16_t pinMask, uint8_t mode)
Configure multiple pins as input or output simultaneously.
Concrete driver for the PCA9570 4‑bit output‑only I2C GPIO expander.
void digitalWritePort(uint16_t mask, uint16_t values) override
Write to multiple pins simultaneously using a mask.
IoExpanderPCA9570 expander
void setup()
#define SENSOR_SCL
#define SENSOR_SDA
void loop()