SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
xl9555_backlight.ino
Go to the documentation of this file.
1
30#include <IoExpanderDrv.hpp>
31#include <AW9364LedDriver.hpp>
32
33#ifdef ENABLE_TFT
34#include "TFT_eSPI.h"
35TFT_eSPI tft;
36#endif
37
38#ifndef SENSOR_SDA
39#define SENSOR_SDA 17
40#endif
41
42#ifndef SENSOR_SCL
43#define SENSOR_SCL 18
44#endif
45
46#ifndef SENSOR_IRQ
47#define SENSOR_IRQ -1
48#endif
49
50// Drive LED pin, corresponding to XL9555 GPIO2
51#define BACKLIGHT_PIN 2
52
55uint8_t level = 0;
56
57void setup()
58{
59 Serial.begin(115200);
60
61 // Set the interrupt input to input pull-up
62 if (SENSOR_IRQ > 0) {
63 pinMode(SENSOR_IRQ, INPUT_PULLUP);
64 }
65
66#ifdef ENABLE_TFT
67 tft.begin();
68 tft.setRotation(1);
69 tft.fillScreen(TFT_GREEN);
70#endif
71
72 /*
73 *
74 * If the device address is not known, the 0xFF parameter can be passed in.
75 *
76 * XL9555_UNKNOWN_ADDRESS = 0xFF
77 *
78 * If the device address is known, the device address is given
79 *
80 * XL9555_SLAVE_ADDRESS0 = 0x20
81 * XL9555_SLAVE_ADDRESS1 = 0x21
82 * XL9555_SLAVE_ADDRESS2 = 0x22
83 * XL9555_SLAVE_ADDRESS3 = 0x23
84 * XL9555_SLAVE_ADDRESS4 = 0x24
85 * XL9555_SLAVE_ADDRESS5 = 0x25
86 * XL9555_SLAVE_ADDRESS6 = 0x26
87 * XL9555_SLAVE_ADDRESS7 = 0x27
88 */
89 const uint8_t chip_address = XL9555_UNKNOWN_ADDRESS;
90
91 if (!expander.begin(Wire, chip_address, SENSOR_SDA, SENSOR_SCL)) {
92 while (1) {
93 Serial.println("Failed to find XL9555 - check your wiring!");
94 delay(1000);
95 }
96 }
97
99
100}
101
102void loop()
103{
104 // 16 dimming levels
105 Serial.print("level:");
106 Serial.println(level);
108 level++;
110 delay(1000);
111}
112
113
114
@license MIT License
constexpr uint8_t MAX_BRIGHTNESS_STEPS
Maximum brightness steps (0‑16).
Controls LED brightness by generating a specific number of pulses on a GPIO pin.
void setBrightness(uint8_t value)
Set the LED brightness level.
void begin(uint8_t pin)
Initialize the driver for use with a native Arduino pin.
bool begin(SensorCommCustom::CustomCallback callback, uint8_t addr)
Initialize the sensor using custom callback interface.
Concrete driver for the XL9555 16‑bit I2C GPIO expander.
AW9364LedDriver ledDriver
void setup()
#define SENSOR_SCL
#define SENSOR_SDA
uint8_t level
#define BACKLIGHT_PIN
#define SENSOR_IRQ
void loop()
IoExpanderXL9555 expander