SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
xl9555_write.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 /*
47 *
48 * If the device address is not known, the 0xFF parameter can be passed in.
49 *
50 * XL9555_UNKNOWN_ADDRESS = 0xFF
51 *
52 * If the device address is known, the device address is given
53 *
54 * XL9555_SLAVE_ADDRESS0 = 0x20
55 * XL9555_SLAVE_ADDRESS1 = 0x21
56 * XL9555_SLAVE_ADDRESS2 = 0x22
57 * XL9555_SLAVE_ADDRESS3 = 0x23
58 * XL9555_SLAVE_ADDRESS4 = 0x24
59 * XL9555_SLAVE_ADDRESS5 = 0x25
60 * XL9555_SLAVE_ADDRESS6 = 0x26
61 * XL9555_SLAVE_ADDRESS7 = 0x27
62 */
63 const uint8_t chip_address = XL9555_UNKNOWN_ADDRESS;
64
65 if (!expander.begin(Wire, chip_address, SENSOR_SDA, SENSOR_SCL)) {
66 while (1) {
67 Serial.println("Failed to find XL9555 - check your wiring!");
68 delay(1000);
69 }
70 }
71
72 // Set PORT0 as output
74}
75
76void loop()
77{
78 // Set all PORTs to 1, and the parameters here are mask values, corresponding to the 0~15 bits
79 Serial.println("Set port HIGH");
80 expander.digitalWritePort(0xFFFF, HIGH);
81 delay(1000);
82
83 Serial.println("Set port LOW");
84 // Set all PORTs to 0, and the parameters here are mask values, corresponding to the 0~15 bits
85 expander.digitalWritePort(0x0000, LOW);
86 delay(1000);
87
88 Serial.println("digitalWrite");
89 expander.digitalWrite(0, HIGH);
90 delay(1000);
91
92 Serial.println("digitalToggle");
94 delay(1000);
95
96
97}
98
99
100
@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 XL9555 16‑bit I2C GPIO expander.
void digitalWritePort(uint16_t mask, uint16_t values) override
Write to multiple pins simultaneously using a mask.
void setup()
#define SENSOR_SCL
#define SENSOR_SDA
void loop()
IoExpanderXL9555 expander