SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
axp517_led.ino
Go to the documentation of this file.
1
30#include <PmicDrv.hpp>
31
32#ifndef PMIC_SDA
33#define PMIC_SDA 3
34#endif
35
36#ifndef PMIC_SCL
37#define PMIC_SCL 2
38#endif
39
40#ifndef PMIC_IRQ
41#define PMIC_IRQ 21
42#endif
43
45
46void setup()
47{
48 Serial.begin(115200);
49 delay(500);
50
51 Serial.println("\n=== AXP517 LED Example ===\n");
52
53 if (!pmic.begin(Wire, AXP517_SLAVE_ADDRESS, PMIC_SDA, PMIC_SCL)) {
54 Serial.println("Failed to init AXP517!");
55 while (1) delay(1000);
56 }
57
58 pmic.enableModule(PmicAXP517::Module::CHGLED, true);
59
60 auto &led = pmic.led();
61
62 Serial.println("\n--- LED Mode Demo ---");
63
64 // 1. AUTO - PMIC controls LED automatically (charge indicator)
66 Serial.println("Mode: AUTO (Charge Indicator)");
67 delay(1000);
68
69 // 2. MANUAL - Manual control
70 led.setMode(PmicLedBase::Mode::MANUAL);
71
72 // Set LED off
73 led.setManualState(PmicLedBase::ManualState::HiZ);
74 Serial.println("Manual: Hi-Z (Off)");
75 delay(1000);
76
77 // Set LED on (low)
78 led.setManualState(PmicLedBase::ManualState::LEVEL_LOW);
79 Serial.println("Manual: LEVEL_LOW (On)");
80 delay(1000);
81
82 // 3. BREATH - Breathing mode
83 led.setMode(PmicLedBase::Mode::BREATH);
84 Serial.println("Mode: BREATH");
85
86 Serial.println("\n=== Setup Complete ===\n");
87}
88
89void loop()
90{
91 static uint8_t state = 0;
92 static uint32_t lastChange = 0;
93
94 if (millis() - lastChange > 3000) {
95 lastChange = millis();
96
97 auto &led = pmic.led();
98
99 switch (state % 5) {
100 case 0:
102 Serial.println("LED: AUTO");
103 break;
104 case 1:
105 led.setMode(PmicLedBase::Mode::MANUAL);
106 led.setManualState(PmicLedBase::ManualState::HiZ);
107 Serial.println("LED: Off");
108 break;
109 case 2:
110 led.setMode(PmicLedBase::Mode::MANUAL);
111 led.setManualState(PmicLedBase::ManualState::LEVEL_LOW);
112 Serial.println("LED: On");
113 break;
114 case 3:
115 led.setMode(PmicLedBase::Mode::MANUAL);
116 led.setManualState(PmicLedBase::ManualState::BLINK_1HZ);
117 Serial.println("LED: BLINK 1HZ");
118 break;
119 case 4:
120 led.setMode(PmicLedBase::Mode::MANUAL);
121 led.setManualState(PmicLedBase::ManualState::BLINK_4HZ);
122 Serial.println("LED: BLINK 4HZ");
123 break;
124 }
125 state++;
126 }
127
128 delay(100);
129}
@license MIT License
PmicAXP517 pmic
#define PMIC_SDA
#define PMIC_SCL
void setup()
void loop()
bool setMode(Mode mode) override
Set the LED mode.
Definition AXP517Led.cpp:55
High-level driver facade for the X-Powers AXP517 PMIC.
bool enableModule(Module module, bool enable)
Enable or disable a functional module.
AXP517Led & led()
Access the AXP517 LED driver.
bool begin(SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
Initialization using a custom communication interface.
@ BREATH
Breath/blink mode controlled by PMIC/hardware (if supported).
@ MANUAL
Manual control through registers.
@ AUTO
PMIC controls LED automatically (e.g.