Skip to content

Commit c3b1919

Browse files
authored
feat(rmt): adds new function to the example
1 parent a4f3e63 commit c3b1919

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

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

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ rmt_data_t blink_1s_rmt_data[] = {
128128
0,
129129
},
130130
// Looping mode needs a Zero ending data to mark the EOF
131-
{0, 0, 0, 0}
131+
{ 0, 0, 0, 0 }
132132
};
133133

134134
// RMT is at 400KHz with a 2.5us tick
@@ -185,7 +185,7 @@ rmt_data_t blink_500ms_rmt_data[] = {
185185
0,
186186
},
187187
// Looping mode needs a Zero ending data to mark the EOF
188-
{0, 0, 0, 0}
188+
{ 0, 0, 0, 0 }
189189
};
190190

191191
// RMT is at 400KHz with a 2.5us tick
@@ -218,7 +218,7 @@ rmt_data_t blink_250ms_rmt_data[] = {
218218
0,
219219
},
220220
// Looping mode needs a Zero ending data to mark the EOF
221-
{0, 0, 0, 0}
221+
{ 0, 0, 0, 0 }
222222
};
223223

224224
void RMT_Mixed_Write_Blink() {
@@ -244,7 +244,8 @@ void RMT_Mixed_Write_Blink() {
244244
Serial.println("===> rmtWrite Blink 0.25s Error!");
245245
}
246246
// wait (blocks) until all the data is sent out
247-
while (!rmtTransmitCompleted(BLINK_GPIO));
247+
while (!rmtTransmitCompleted(BLINK_GPIO))
248+
;
248249
}
249250
Serial.println("Blinking OFF for 1 seconds");
250251
delay(1000);
@@ -269,13 +270,34 @@ void RMT_Loop_Write_Blink() {
269270
delay(5000);
270271

271272
Serial.println("Blinking OFF for 2 seconds");
272-
rmt_data_t blink_STOP_rmt_data[] = {{0, 0, 0, 0}};
273+
rmt_data_t blink_STOP_rmt_data[] = { { 0, 0, 0, 0 } };
273274
if (!rmtWrite(BLINK_GPIO, blink_STOP_rmt_data, RMT_SYMBOLS_OF(blink_STOP_rmt_data), RMT_WAIT_FOR_EVER)) {
274275
Serial.println("===> rmtWrite Blink STOP Error!");
275276
}
276277
delay(2000);
277278
}
278279

280+
void RMT_Repeated_Write_Blink() {
281+
Serial.println("Using RMT Writing repeated N times to blink an LED.");
282+
Serial.println("Blinking at 1s on + 1s off :: 2 blinks");
283+
// repeating blink_1s_rmt_data (1s on + 1s off) 2 times for 2 blinks
284+
if (!rmtWriteRepeated(BLINK_GPIO, blink_1s_rmt_data, RMT_SYMBOLS_OF(blink_1s_rmt_data) - 1, 2)) {
285+
Serial.println("===> rmtWrite Blink 1s Error!");
286+
}
287+
Serial.println("Blinking at 500ms on + 500ms off :: 4 blinks");
288+
// repeating blink_500ms_rmt_data (500ms on + 500ms off) 4 times for 4 blinks
289+
if (!rmtWriteRepeated(BLINK_GPIO, blink_500ms_rmt_data, RMT_SYMBOLS_OF(blink_500ms_rmt_data) - 1, 4)) {
290+
Serial.println("===> rmtWrite Blink 0.5s Error!");
291+
}
292+
Serial.println("Blinking at 250ms on + 250ms off :: 8 blinks");
293+
// repeating blink_250ms_rmt_data (250ms on + 250ms off) 8 times for 8 blinks
294+
if (!rmtWriteRepeated(BLINK_GPIO, blink_250ms_rmt_data, RMT_SYMBOLS_OF(blink_250ms_rmt_data) - 1, 8)) {
295+
Serial.println("===> rmtWrite Blink 0.25s Error!");
296+
}
297+
Serial.println("Blinking is OFF for 2 seconds");
298+
delay(2000);
299+
}
300+
279301
void RMT_Single_Write_Blocking_Blink() {
280302
Serial.println("Using RMT Writing and its Completion to blink an LED.");
281303
Serial.println("Blinking at 1s on + 1s off :: 2 blinks");
@@ -308,23 +330,26 @@ void RMT_Write_Aync_Non_Blocking_Blink() {
308330
Serial.println("===> rmtWrite Blink 1s Error!");
309331
}
310332
// wait (blocks) until all the data is sent out
311-
while (!rmtTransmitCompleted(BLINK_GPIO));
333+
while (!rmtTransmitCompleted(BLINK_GPIO))
334+
;
312335
}
313336
Serial.println("Blinking at 500ms on + 500ms off :: 5 blinks");
314337
for (uint8_t i = 0; i < 5; i++) {
315338
if (!rmtWriteAsync(BLINK_GPIO, blink_500ms_rmt_data, RMT_SYMBOLS_OF(blink_500ms_rmt_data) - 1)) {
316339
Serial.println("===> rmtWrite Blink 0.5s Error!");
317340
}
318341
// wait (blocks) until all the data is sent out
319-
while (!rmtTransmitCompleted(BLINK_GPIO));
342+
while (!rmtTransmitCompleted(BLINK_GPIO))
343+
;
320344
}
321345
Serial.println("Blinking at 250ms on + 250ms off :: 5 blinks");
322346
for (uint8_t i = 0; i < 5; i++) {
323347
if (!rmtWriteAsync(BLINK_GPIO, blink_250ms_rmt_data, RMT_SYMBOLS_OF(blink_250ms_rmt_data) - 1)) {
324348
Serial.println("===> rmtWrite Blink 0.25s Error!");
325349
}
326350
// wait (blocks) until all the data is sent out
327-
while (!rmtTransmitCompleted(BLINK_GPIO));
351+
while (!rmtTransmitCompleted(BLINK_GPIO))
352+
;
328353
}
329354
Serial.println("Blinking OFF for 1 seconds");
330355
delay(1000);
@@ -356,6 +381,7 @@ void setup() {
356381
void loop() {
357382
RMT_Write_Aync_Non_Blocking_Blink();
358383
RMT_Loop_Write_Blink();
384+
RMT_Repeated_Write_Blink();
359385
RMT_Single_Write_Blocking_Blink();
360386
Serial.println("\nStarting OVER...\n");
361387
}

0 commit comments

Comments
 (0)