🛠 GPIO et PWM sur le Teensy 4.1 : 55 broches en 3,3 V, ni 5 V tolérées ni traîne

Teensy 4.1 · debutant · Schéma : rangées de broches du Teensy 4.1 sur plaque de prototypage — 42 broches facilement accessibles sans breadboard, dont les broches supplémentaires 24, 25, 46, 47 et 53 absentes du Teensy 4.0 ; rappel « 3,3 V max, non tolérantes 5 V » sur chaque broche.

Objectives

Leverage the Teensy 4.1 I/O: 55 pins in total, with 42 easily accessible on a solderless breadboard (compared to 40/24 on the 4.0). The additional row provides dedicated PWM pins (24, 25, 46, 47, 53 are listed in the official PWM map). We will read a button, generate brightness variation via PWM, and internalize the two golden rules: no pin tolerates more than 3.3 V (a radical change from the Teensy 3.2!) and the recommended output current is 4 mA per pin (a conservative value from the product page).

Hardware

Electrical Rules

Complete Code

const uint8_t BTN = 24;     // broche exclusive du 4.1
const uint8_t LED_PWM = 6;  // broche FlexPWM
const uint8_t LED_STAT = 13;// LED orange : jamais INPUT_PULLUP ici

void setup {
  pinMode(BTN, INPUT_PULLUP);
  pinMode(LED_STAT, OUTPUT);
  analogWriteFrequency(LED_PWM, 1000); // 1 kHz, indépendant des autres groupes
  analogWrite(LED_PWM, 0);
}

void loop {
  if (digitalRead(BTN) == LOW) {
    // A0 (broche 14) : 0..1023 sur 0..3,3 V fixes
    int v = map(analogRead(14), 0, 1023, 0, 255);
    analogWrite(LED_PWM, v);
    digitalWrite(LED_STAT, HIGH);
  } else {
    analogWrite(LED_PWM, 0);
    digitalWrite(LED_STAT, LOW);
  }
  delay(10);
}

Expected Verification

Button released: LED off. Button pressed: brightness follows the potentiometer. The 600 MHz M7 with its TCM memories makes pin writes negligible in CPU cycles — for high-frequency blinking, prefer digitalToggle (a single compiled bit write).

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials