🛠 Bouton MODE et console série
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
- 1 Particle Photon board (onboard Setup and Reset buttons, confirmed by the datasheet)
- 1 micro-USB cable
- A serial terminal (Particle CLI:
particle serial monitor, or any monitor at 9600 baud)
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
- Holding SETUP and then pressing RESET: this is the combination that makes the Photon blink yellow for DFU flashing, not a simple press.
- Forgetting INPUT_PULLUP: the input floats and the button triggers without being pressed.
- A long press on SETUP starts Wi-Fi configuration (Soft AP mode) and may cut your serial session.
- Do not forget that the USB serial port is disconnected during certain configuration phases.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-evenement.inoArduinofonction-distance.inoArduinocapteur-dht.inoArduinoruban-neopixel.inoArduinopwm-respiration.inoArduino