Skip to content

Commit e92b4ca

Browse files
authored
Add: make digitalRead() for RGB_BUILTIN work (#9419)
* make digitalRead() for RGB_BUILTIN work Standard Arduino-Way of blinking a LED can be the shortest with: void loop() { static uint32_t ledticker = 0; if (millis() - ledticker > 1000) { ledticker = millis(); digitalWrite(RGB_BUILTIN, !digitalRead(RGB_BUILTIN)); } } Worked with the old LED_BUILTIN on Pin 2, now even works with Pin 48/neopixel. * Add: make digitalRead() for RGB_BUILTIN work Standard Arduino-Way of blinking a LED can be the shortest with: void loop() { static uint32_t ledticker = 0; if (millis() - ledticker > 1000) { ledticker = millis(); digitalWrite(RGB_BUILTIN, !digitalRead(RGB_BUILTIN)); } } Worked with the old LED_BUILTIN on Pin 2, now even works with Pin 48/neopixel. (Retry. Didn't sync my local sources. Sorry.)
1 parent 6345350 commit e92b4ca

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Diff for: cores/esp32/esp32-hal-gpio.c

+11
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,16 @@ extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode)
151151
}
152152
}
153153

154+
#ifdef RGB_BUILTIN
155+
uint8_t RGB_BUILTIN_storage = 0;
156+
#endif
157+
154158
extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val)
155159
{
156160
#ifdef RGB_BUILTIN
157161
if(pin == RGB_BUILTIN){
158162
//use RMT to set all channels on/off
163+
RGB_BUILTIN_storage=val;
159164
const uint8_t comm_val = val != 0 ? RGB_BRIGHTNESS : 0;
160165
neopixelWrite(RGB_BUILTIN, comm_val, comm_val, comm_val);
161166
return;
@@ -170,6 +175,12 @@ extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val)
170175

171176
extern int ARDUINO_ISR_ATTR __digitalRead(uint8_t pin)
172177
{
178+
#ifdef RGB_BUILTIN
179+
if(pin == RGB_BUILTIN){
180+
return RGB_BUILTIN_storage;
181+
}
182+
#endif
183+
173184
if(perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL){
174185
return gpio_get_level((gpio_num_t)pin);
175186
}

0 commit comments

Comments
 (0)