SensorLib 0.5.1
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
aw9523_gpio.ino
Go to the documentation of this file.
1
7#include <IoExpanderDrv.hpp>
8
9#ifndef SENSOR_SDA
10#define SENSOR_SDA 17
11#endif
12
13#ifndef SENSOR_SCL
14#define SENSOR_SCL 18
15#endif
16
17static constexpr uint8_t OUTPUT_PIN = 0; // P0_0
18static constexpr uint8_t INPUT_PIN = 1; // P0_1, requires an external pull-up/down
19
21
22void setup()
23{
24 Serial.begin(115200);
25
26 if (!expander.begin(Wire, AW9523_DEFAULT_ADDRESS, SENSOR_SDA, SENSOR_SCL)) {
27 while (1) {
28 Serial.println("Failed to find AW9523 - check your wiring and address pins!");
29 delay(1000);
30 }
31 }
32
33 // P0 defaults to open-drain. Select push-pull for a directly driven output.
35 expander.pinMode(OUTPUT_PIN, OUTPUT);
36 expander.pinMode(INPUT_PIN, INPUT);
37
38 // INTN is active-low and open-drain. Reading P0 clears P0 interrupts.
39 expander.enableInterrupt(INPUT_PIN);
40}
41
42void loop()
43{
44 expander.digitalToggle(OUTPUT_PIN);
45
46 Serial.print("P0_1: ");
47 Serial.println(expander.digitalRead(INPUT_PIN) ? "HIGH" : "LOW");
48 delay(500);
49}
@license MIT License
IoExpanderAW9523 expander
void setup()
#define SENSOR_SCL
#define SENSOR_SDA
void loop()
bool begin(SensorCommCustom::CustomCallback callback, uint8_t addr)
Initialize the sensor using custom callback interface.
Driver for the AW9523/AW9523B 16-channel GPIO and LED controller.
bool setPort0PushPull(bool pushPull)
Select the P0 GPIO output driver type.
bool enableInterrupt(uint8_t pin, bool enable=true)
Enable or disable input-change interrupt generation for one pin.
void digitalToggle(uint8_t pin)
Toggle the state of an output pin.
bool digitalRead(uint8_t pin)
Read the digital value from an input pin.
void pinMode(uint8_t pin, uint8_t mode)
Set the direction of a GPIO pin.