clignotante.ino

ESP32-S3 · 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-S3 board (dual-core Xtensa with vector instructions, Wi-Fi + BLE 5, native USB) such as a DevKitC-1, XIAO or T-Display-S3, powered over USB. Nothing: the onboard user LED is enough (otherwise LED + 330 Ω resistor).

Wiring

Pin 48 (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 « ESP32S3 Dev Module », enable « USB CDC On Boot », then Upload. Many boards put a WS2812 on GPIO48.

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-s3 (millis au lieu de delay).
const int LED = 48;          // 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