clignotante.ino

Teensy 3.2 · File : clignotante.ino · Language : Arduino · Use case : Faire clignoter la LED intégrée à 1 Hz

The pin 13 LED blinks at 1 Hz, driven from the SysTick interrupt: loop() stays fully free. A typical pattern on Teensy boards, whose ARM Cortex-M core handles real hardware interrupts.

Hardware

A Teensy 3.2 (NXP Kinetis MK20DX256, Cortex-M4 @ 72 MHz, 3.3 V logic) powered over USB. No external component; the onboard user LED is enough.

Wiring

Nothing to wire for LED 13. Note: Teensy pins work at 3.3 V, not 5 V.

How it works

The systick_loop() function, a Teensyduino specific, is called every millisecond by the kernel; it checks millis() and toggles the pin. Shared variables are volatile to avoid compiler optimizations.

Running it

Install the Teensyduino plugin in the Arduino IDE, select the « Teensy 3.2 » board, click Upload then the Teensy Loader button. Note: 3.3 V pins.

Variants

A simple version with delay(500) in loop(), or two LEDs at different rates by duplicating the logic with a period table.

clignotante.ino

// Clignotement LED sur la broche 13 (LED utilisateur Teensy).
const int LED = 13;

volatile bool etat = false;
volatile uint32_t dernierBlink = 0;

// systick_loop() est une specificite Teensy : appelee chaque ms
// par le noyau, la LED clignote meme si loop() est occupee ailleurs.
void systick_loop() {
  uint32_t maintenant = millis();
  if (maintenant - dernierBlink >= 1000) {
    dernierBlink = maintenant;
    etat = !etat;
    digitalWrite(LED, etat);
  }
}

void setup() {
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
  while (!Serial && millis() < 2000); // attend l'ouverture du moniteur
  Serial.println(F("Clignotement Teensy demarre"));
}

void loop() {
  // Le coeur de travail est dans systick_loop() : loop() reste
  // 100 % disponible pour d'autres traitements.
}

← Back to the board