bouton-poussoir.ino

Arduino Portenta H7 · File : bouton-poussoir.ino · Language : Arduino · Use case : Lire un bouton avec anti-rebond sur la Portenta

The button/LED circuit ports as-is to the Portenta: the Arduino Mbed core offers INPUT_PULLUP and digitalRead with the same semantics. The comment already eyes the interrupt version for low-power mode.

Hardware

An Arduino Portenta H7 (ST STM32H747 dual-core module Cortex-M7 @ 480 MHz + M4 @ 240 MHz, 8 MB SDRAM, high-density connector), powered by USB-C or 5 V. 1 push button + wire to GND.

Wiring

Button between connector pin D2 and GND (internal pull-up). Check the carrier board schematic for pin mapping.

How it works

Level validated after 30 ms of stability; the press (LOW) lights the LED and prints over USB-C.

Running it

Arduino IDE with the « Arduino Mbed OS Portenta Boards » core: pick « Portenta H7 » (M7 core), the USB-C port, then Upload. The DFU mode M7/M4 selector also loads the M4 core.

Variants

Switch to an interrupt (attachInterrupt) to wake the board from sleep, or debounce in hardware (RS flip-flop).

bouton-poussoir.ino

// Bouton sur D2 (vers GND) + LED, anti-rebond 30 ms.
const int BOUTON = 2;

bool stable = HIGH, precedent = HIGH;
unsigned long dernierBord = 0;

void setup() {
  pinMode(BOUTON, INPUT_PULLUP);
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  bool lecture = digitalRead(BOUTON);
  unsigned long maintenant = millis();

  if (lecture != precedent) dernierBord = maintenant;
  if (maintenant - dernierBord >= 30 && lecture != stable) {
    stable = lecture;
    digitalWrite(LED_BUILTIN, stable == LOW);
    Serial.println(stable == LOW ? "appui" : "relache");
  }
  precedent = lecture;

  // A 480 MHz, boucle de polling ne coute rien ; en basse
  // consommation, mieux vaudrait une interruption EXTI.
}

← Back to the board