Skip to content

Commit 6e334a6

Browse files
authored
feat(rmt): fixes exaple to run correctly within IDF 5.x
1 parent 571c2f7 commit 6e334a6

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

libraries/ESP32/examples/RMT/RMT_LED_Blink/RMT_LED_Blink.ino

+23-22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 Espressif Systems (Shanghai) PTE LTD
1+
// Copyright 2025 Espressif Systems (Shanghai) PTE LTD
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -13,16 +13,16 @@
1313
// limitations under the License.
1414

1515
/**
16-
* @brief This example demonstrate how to use RMT to just blink a regular LED (GPIO)
17-
* It uses all the different RMT Writing APIs to blink the LED by hardware, not being
18-
* necessary the regular Blink code in Arduino.
19-
*
20-
* The output is the Blinking LED in the GPIO and a serial output describing what is
21-
* going on, along the execution.
22-
*
23-
* The circuit is just a LED and a resistor of 270 ohms connected to the GPIO
24-
* GPIO ---> resistor 270 ohms ---> + LED - ---> GND
25-
*/
16+
@brief This example demonstrate how to use RMT to just blink a regular LED (GPIO)
17+
It uses all the different RMT Writing APIs to blink the LED by hardware, not being
18+
necessary the regular Blink code in Arduino.
19+
20+
The output is the Blinking LED in the GPIO and a serial output describing what is
21+
going on, along the execution.
22+
23+
The circuit is just a LED and a resistor of 270 ohms connected to the GPIO
24+
GPIO ---> resistor 270 ohms ---> + LED - ---> GND
25+
*/
2626

2727
#define BLINK_GPIO 2
2828

@@ -232,15 +232,15 @@ void RMT_Mixed_Write_Blink() {
232232
Serial.println("===> rmtWrite() (Blocking Mode) to Blink the LED.");
233233
Serial.println("Blinking at 500ms on + 500ms off :: 4 blinks");
234234
for (uint8_t i = 0; i < 4; i++) {
235-
if (!rmtWrite(BLINK_GPIO, blink_500ms_rmt_data, RMT_SYMBOLS_OF(blink_500ms_rmt_data) - 2, RMT_WAIT_FOR_EVER)) {
235+
if (!rmtWrite(BLINK_GPIO, blink_500ms_rmt_data, RMT_SYMBOLS_OF(blink_500ms_rmt_data) - 1, RMT_WAIT_FOR_EVER)) {
236236
Serial.println("===> rmtWrite Blink 0.5s Error!");
237237
}
238238
}
239239

240240
Serial.println("===> rmtWriteAsync() (Non-Blocking Mode) to Blink the LED.");
241241
Serial.println("Blinking at 250ms on + 250ms off :: 5 blinks");
242242
for (uint8_t i = 0; i < 5; i++) {
243-
if (!rmtWriteAsync(BLINK_GPIO, blink_250ms_rmt_data, RMT_SYMBOLS_OF(blink_250ms_rmt_data) - 2)) {
243+
if (!rmtWriteAsync(BLINK_GPIO, blink_250ms_rmt_data, RMT_SYMBOLS_OF(blink_250ms_rmt_data) - 1)) {
244244
Serial.println("===> rmtWrite Blink 0.25s Error!");
245245
}
246246
// wait (blocks) until all the data is sent out
@@ -267,9 +267,11 @@ void RMT_Loop_Write_Blink() {
267267
Serial.println("===> rmtWriteLooping Blink 0.25s Error!");
268268
}
269269
delay(5000);
270+
270271
Serial.println("Blinking OFF for 2 seconds");
271-
if (!rmtWriteLooping(BLINK_GPIO, NULL, 0)) {
272-
Serial.println("===> rmtWriteLooping Blink OFF Error!");
272+
rmt_data_t blink_STOP_rmt_data[] = { {0, 0, 0, 0} };
273+
if (!rmtWrite(BLINK_GPIO, blink_STOP_rmt_data, RMT_SYMBOLS_OF(blink_STOP_rmt_data), RMT_WAIT_FOR_EVER)) {
274+
Serial.println("===> rmtWrite Blink STOP Error!");
273275
}
274276
delay(2000);
275277
}
@@ -278,19 +280,19 @@ void RMT_Single_Write_Blocking_Blink() {
278280
Serial.println("Using RMT Writing and its Completion to blink an LED.");
279281
Serial.println("Blinking at 1s on + 1s off :: 2 blinks");
280282
for (uint8_t i = 0; i < 2; i++) {
281-
if (!rmtWrite(BLINK_GPIO, blink_1s_rmt_data, RMT_SYMBOLS_OF(blink_1s_rmt_data) - 2, RMT_WAIT_FOR_EVER)) {
283+
if (!rmtWrite(BLINK_GPIO, blink_1s_rmt_data, RMT_SYMBOLS_OF(blink_1s_rmt_data) - 1, RMT_WAIT_FOR_EVER)) {
282284
Serial.println("===> rmtWrite Blink 1s Error!");
283285
}
284286
}
285287
Serial.println("Blinking at 500ms on + 500ms off :: 4 blinks");
286288
for (uint8_t i = 0; i < 4; i++) {
287-
if (!rmtWrite(BLINK_GPIO, blink_500ms_rmt_data, RMT_SYMBOLS_OF(blink_500ms_rmt_data) - 2, RMT_WAIT_FOR_EVER)) {
289+
if (!rmtWrite(BLINK_GPIO, blink_500ms_rmt_data, RMT_SYMBOLS_OF(blink_500ms_rmt_data) - 1, RMT_WAIT_FOR_EVER)) {
288290
Serial.println("===> rmtWrite Blink 0.5s Error!");
289291
}
290292
}
291293
Serial.println("Blinking at 250ms on + 250ms off :: 8 blinks");
292294
for (uint8_t i = 0; i < 8; i++) {
293-
if (!rmtWrite(BLINK_GPIO, blink_250ms_rmt_data, RMT_SYMBOLS_OF(blink_250ms_rmt_data) - 2, RMT_WAIT_FOR_EVER)) {
295+
if (!rmtWrite(BLINK_GPIO, blink_250ms_rmt_data, RMT_SYMBOLS_OF(blink_250ms_rmt_data) - 1, RMT_WAIT_FOR_EVER)) {
294296
Serial.println("===> rmtWrite Blink 0.25s Error!");
295297
}
296298
}
@@ -302,23 +304,23 @@ void RMT_Write_Aync_Non_Blocking_Blink() {
302304
Serial.println("Using RMT Async Writing and its Completion to blink an LED.");
303305
Serial.println("Blinking at 1s on + 1s off :: 5 blinks");
304306
for (uint8_t i = 0; i < 5; i++) {
305-
if (!rmtWriteAsync(BLINK_GPIO, blink_1s_rmt_data, RMT_SYMBOLS_OF(blink_1s_rmt_data) - 2)) {
307+
if (!rmtWriteAsync(BLINK_GPIO, blink_1s_rmt_data, RMT_SYMBOLS_OF(blink_1s_rmt_data) - 1)) {
306308
Serial.println("===> rmtWrite Blink 1s Error!");
307309
}
308310
// wait (blocks) until all the data is sent out
309311
while (!rmtTransmitCompleted(BLINK_GPIO));
310312
}
311313
Serial.println("Blinking at 500ms on + 500ms off :: 5 blinks");
312314
for (uint8_t i = 0; i < 5; i++) {
313-
if (!rmtWriteAsync(BLINK_GPIO, blink_500ms_rmt_data, RMT_SYMBOLS_OF(blink_500ms_rmt_data) - 2)) {
315+
if (!rmtWriteAsync(BLINK_GPIO, blink_500ms_rmt_data, RMT_SYMBOLS_OF(blink_500ms_rmt_data) - 1)) {
314316
Serial.println("===> rmtWrite Blink 0.5s Error!");
315317
}
316318
// wait (blocks) until all the data is sent out
317319
while (!rmtTransmitCompleted(BLINK_GPIO));
318320
}
319321
Serial.println("Blinking at 250ms on + 250ms off :: 5 blinks");
320322
for (uint8_t i = 0; i < 5; i++) {
321-
if (!rmtWriteAsync(BLINK_GPIO, blink_250ms_rmt_data, RMT_SYMBOLS_OF(blink_250ms_rmt_data) - 2)) {
323+
if (!rmtWriteAsync(BLINK_GPIO, blink_250ms_rmt_data, RMT_SYMBOLS_OF(blink_250ms_rmt_data) - 1)) {
322324
Serial.println("===> rmtWrite Blink 0.25s Error!");
323325
}
324326
// wait (blocks) until all the data is sent out
@@ -345,7 +347,6 @@ void setup() {
345347

346348
RMT_Mixed_Write_Blink();
347349
Serial.println("End of Mixed Calls testing");
348-
delay(1000);
349350

350351
Serial.println("\n===============================");
351352
Serial.println("Starting a Blinking sequence...");

0 commit comments

Comments
 (0)