🛠 Bouton MODE et console série

Particle Photon · debutant · Schéma : IMG-particle-photon-debutant-2-photon-bouton-console.svg — Photon avec les boutons SETUP (MODE) et RESET annotés et le câble USB vers l'ordinateur

Objectives

Read the state of the Photon's onboard button (the SETUP button, accessible in software as MODE), display it on the USB serial console, and familiarize yourself with the two physical buttons, SETUP and RESET, which are also used for DFU flashing.

Hardware

Complete Code

// photon-bouton-console.ino — bouton MODE + console série
const int BTN = MODE;          // bouton SETUP mappé sur la broche MODE
// > 
// décrits dans la fiche ; vérifier dans la Device OS API reference.

volatile bool pressed = false;

void onButton { pressed = true; }

void setup {
  pinMode(BTN, INPUT_PULLUP);
  attachInterrupt(BTN, onButton, RISING);
  Serial.begin(9600);
  Serial.println("Console prete : appuyez sur SETUP");
}

void loop {
  if (pressed) {
    pressed = false;
    Serial.println("Bouton SETUP presse !");
  }
  delay(10);
}

Expected Verification

After flashing, particle serial monitor displays the welcome message; each press of the SETUP button prints a line. Take this opportunity to test RESET: a short press restarts the program (the welcome message reappears).

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials