🛠 Bouton et LED sur les GPIO de la Tian : les bases côté SAMD21

Arduino Tian (id: tian) · debutant · Schéma : IMG-tian-debutant-2-tian-bouton-led-gpio.svg — Arduino Tian sur breadboard : bouton poussoir entre un picot d'E/S et GND, LED avec résistance 330 Ω sur un autre picot, double rangée de broches mise en évidence.

Objectives

Control an output and read an input on the Tian's I/O pins driven by the SAMD21: internal pull-up, active-low logic, and discovering the pinout peculiarity — analog inputs A6 to A11 share pins with digital pins 4, 6, 8, 9, 10, and 12, which can cause function conflicts if you don't check the schematic.

Hardware

Complete Code

// Bouton sur D2 (vers GND), LED sur D13.
const uint8_t BTN = 2;
const uint8_t LED = 13;

void setup {
  pinMode(BTN, INPUT_PULLUP);   // repos = HIGH, appuyé = LOW
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
}

void loop {
  bool appuye = (digitalRead(BTN) == LOW);   // logique inversée
  digitalWrite(LED, appuye ? HIGH : LOW);
  if (appuye) Serial.println(F("bouton appuyé"));
  delay(20);
}

Expected Verification

LED off at rest, on when pressed; the Serial Monitor displays a message while pressed. Touch the D2 wire without the button: the input floats and the state becomes random — the internal pull-up is indeed what stabilizes the circuit.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials