clavier_media.ino

LattePanda 3 Delta (id: lattepanda-3) · File : clavier_media.ino · Language : Arduino · Use case : Tourner le bouton physique en touche clavier USB

The 32U4 is a full USB device: a header button becomes a media key sent to... the LattePanda host itself. The complete circuit button → HID → system, no wires, no drivers.

Hardware required

A LattePanda 3 Delta (x86 Intel N5105, Windows 10/11 or Ubuntu) with its Arduino-compatible co-processor (ATmega32U4) wired to the two 50-pin headers. 1 push button (D2 to GND).

Wiring

Button between D2 and GND. The MCU links to the host over the internal serial bus — the USB HID leaves the 32U4 toward the PC via the internal controller.

How it works

Keyboard.write sends a standard HID report; the host kernel treats it as a real keyboard. Holding paces repeats at 1 Hz. Host side: pip install pinpong then python3. MCU side: the ATmega32U4 shows up as a COM port — program it with the Arduino IDE (« Arduino Leonardo » board).

Going further

A shortcut pad for the studio (mute mic, play), or a keyboard+mouse combo for presentations.

clavier_media.ino

// Cote MCU (carte « Arduino Leonardo ») : le 32U4 est le clavier.
// Bouton D2 = touche volume +/- ; le PC (l'hote !) recoit les medias.
#include <Keyboard.h>

const int BOUTON = 2;

void setup() {
  pinMode(BOUTON, INPUT_PULLUP);
  Keyboard.begin();
}

void loop() {
  if (digitalRead(BOUTON) == LOW) {
    Keyboard.write(KEY_MEDIA_VOLUME_UP);
    delay(150);                       // repetition volontairement lente
    while (digitalRead(BOUTON) == LOW) {
      if (millis() % 1000 < 20) Keyboard.write(KEY_MEDIA_VOLUME_UP);
      delay(5);
    }
  }
  // Raccourcis utiles : KEY_MEDIA_PLAY_PAUSE, KEY_LEFT_GUI...
}

← Back to the board