Three LEDs with Dirty Delay (ESP32)

So, I received my ESP32 recently and I wanted to show you guys how to set it up so you can actually use he very dirty Delay function without messing up the wonderful world of Blynk.

Note: this project is NOT affiliated with @Gunner his flashy light led blynky thing! :wink:

So, ESP32 has actually got two cores. If you setup the board in the IDE so you can program it, you can also address the two different cores and run your sketch in a multithreaded fashion. As demonstrated by the below code. It flashes three LED’s on V1, V2 and V3 with a big dirty loop full of delays!

#define BLYNK_PRINT Serial

#include <Arduino.h> // This include is only needed if you build on PlatformIO
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char auth[] = "charstuff";

char ssid[] = "wifistuff";
char pass[] = "morewifistuff";

WidgetLED led1(V1);
WidgetLED led2(V2);
WidgetLED led3(V3);

// Dirty loop with delays, YUCK!
void loop1(void *pvParameters)
  while (1)
    if (led1.getValue()) {;
    } else { led1.on(); }

    if (led2.getValue()) {;
    } else { led2.on(); }

    if (led3.getValue()) {;
    } else { led3.on(); }

// And running blynk stuff on other loop. Note the 1ms delay, this is need so the watchdog doesn't get confused
void loop2(void *pvParameters) {
  while (1) {;

void setup()

  Blynk.begin(auth, ssid, pass, "serverstuffhere or cloud", 8442);

  // Here we create what is normally a timer thing
  // Note the last argument, this is the Core of the ESP it will run on!
  xTaskCreatePinnedToCore(loop1, "loop1", 4096, NULL, 1, NULL, 0);
  xTaskCreatePinnedToCore(loop2, "loop2", 4096, NULL, 1, NULL, 1);

void loop()
// And an emtpy loop!



very interesting. i didn’t know about this. where can i read more detailed docs about it?

Well, this is totally unsupported I think. The ESP32 is still in beta stage. I’ve found the info here and added Blynk in the loop, sort of speak … :smiley:


but in the reality these 2 loops indeed run completely isolated? i mean no matter what is happening in loop1, loop2 can do blynk and wifi stuff?

that whould be a great help for time sensitive functions and stepper motor control for example!

Yes. They run on physically different CPU cores of the ESP32 because it has two Cores.

very cool! thanks for shareing :wink:

That is awesome!

One thing missing though, I haven’t got any Blynk debug output on the Serial port. So that would require some attention. Not sure why not. Other Serial output is fine.

That’s only because your rebel trio of LEDs is no match for the Blinky firepower of my fully operational battlestation of 72 LEDs :stuck_out_tongue:

However, it may have more practical applications… :blush:

That worked OK on Arduino IDE… perhaps a PlatformIO issue?

1 Like

On that “spare” void loop, which will also run stuff… which core does it use?

That is user-specified, it seems! Last argument as per comment

  // Here we create what is normally a timer thing
  // Note the last argument, this is the Core of the ESP it will run on!
  xTaskCreatePinnedToCore(loop1, "loop1", 4096, NULL, 1, NULL, 0);
  xTaskCreatePinnedToCore(loop2, "loop2", 4096, NULL, 1, NULL, 1);
1 Like

I use CoolTerm for serial monitoring. Guess it could be me. I’m just glad I can separate all the task for now. This opens up a whole new range of possibilities (mostly dirty programming, lol).

@Fettkeewl I guess then that since it is the “default” loop and otherwise unspecified, it probably runs on the default core… 0? EDIT - Nope, Core 1, based on one of those documents @Lichtsignaal posted below.

I knew the ESP had dual cores, but I thought the 2nd one was dedicated to the WiFi interface… this calls for more investigation… Meanwhile I must rethink which ESP to put in my rover as this might greatly improve its functionality without a massive timer investment.

More info here on the specific functions you can use with xTaskCreate stuff.

And even mroe here: ESP32: Running code on a specific core - techtutorialsx (this is a good one I think).

@Gunner I think it also depends on the Priority settings, from what I can gather when creating the task


A side question, did you try the ADC On esp32?

I just read that it has 2 ADCs supporting 9 channels each, I was wondering if that meant that
each ADC could handle 9 different adc readings in sequence?
Or is it limited to 1 channel per adc but you can choose which one?

No idea, haven’t ADC yet, but I’ll try and see if I can add some analog stuff to it. If I can find some sensors… lol.


If I look at the pictures it just has 9 analog ports, or so it sems.

Crap, it even has 10(!!!) integrated touch sensors. This means you can use a simple copperclad board to create a keypad for example :smiley:

Pretty cool eh… This will be a sweet Blynk board once all the teething issues are worked out… OTA, BLE, WiFi, Touch, Multiple UARTS, Dual Core, Fast, lots of IO, etc.

Unfortunately the latest Update IDF libs broke something in ArduinoOTA… so that doesn’t work, and I have no idea how to revert to the “prior” update :blush: So much new too fast.

EDIT - It has been fixed now :smiley: Now I just have to figure out how to get it to work more than once… something is different in the required commands then with the ESP8266.

Looks fun :smile:

ADC works here is demo:

1 Like