clignotante.ino

ESP32-S2 · File : clignotante.ino · Language : Arduino · Use case : Faire clignoter une LED sans bloquer la boucle

The board's sanity check: the LED blinks at 1 Hz using millis() instead of delay(), leaving the loop free for Wi-Fi or sensors. The monitor also prints free heap — handy before adding radio libraries.

Hardware required

An ESP32-S2 board (single-core Xtensa, Wi-Fi, native USB-OTG on GPIO19/20, 14 capacitive touch pads) such as a DevKitC-1 or QT Py, powered over USB. Nothing: the onboard user LED is enough (otherwise LED + 330 Ω resistor).

Wiring

Pin 2 (onboard LED on most DevKit boards); otherwise anode through 330 Ω, cathode to GND.

How it works

millis() counts elapsed milliseconds; when the gap exceeds the period the pin flips. No blocking delay: loop() can run at full speed. In the Arduino IDE (esp32 package), select « ESP32S2 Dev Module »; the S2 flashes straight over its native USB (double reset on some boards to enter the bootloader).

Going further

Wire two LEDs and alternate them, or vary the period with a potentiometer on an ADC pin.

clignotante.ino

// Clignotement non bloquant sur la carte esp32-s2 (millis au lieu de delay).
const int LED = 2;          // LED utilisateur de la plupart des cartes
const unsigned long PERIODE = 500;  // ms

bool etat = false;
unsigned long precedent = 0;

void setup() {
  pinMode(LED, OUTPUT);
  Serial.begin(115200);
  Serial.println("Clignotement demarre");
}

void loop() {
  unsigned long t = millis();
  if (t - precedent >= PERIODE) {
    precedent = t;
    etat = !etat;
    digitalWrite(LED, etat ? HIGH : LOW);
    Serial.printf("LED %s — heap libre : %u\n", etat ? "ON" : "OFF", ESP.getFreeHeap());
  }
}

← Back to the board