🛠 Bouton poussoir et console série avec le coprocesseur

LattePanda Alpha · debutant · Schéma : IMG-lattepanda-alpha-debutant-2-bouton-serie.svg — bouton poussoir sur D2 vers la masse avec résistance de pull-up interne, LED sur D13

Objectives

Add a digital input to the LattePanda Alpha's ATmega32U4 coprocessor: a push button read with an internal pull-up resistor, an LED that lights up in response, and most importantly the internal USB serial link connecting the ATmega32U4 to the x86 PC (Core m3-7Y30). This is the fundamental building block for all SoC ↔ MCU communication on this board.

Hardware

Complete Code

// BlinkAndButton.ino — téléverser sur le coprocesseur, carte "Arduino Leonardo"
const int LED_PIN = 13;   // broche numérique compatible Arduino
const int BTN_PIN = 2;    // bouton de D2 vers GND (pull-up interne utilisé)

void setup {
  pinMode(LED_PIN, OUTPUT);
  pinMode(BTN_PIN, INPUT_PULLUP);
  Serial.begin(9600);     // série USB vers le côté x86 (COM sous Windows, /dev/ttyACM* sous Linux)
}

void loop {
  digitalWrite(LED_PIN, digitalRead(BTN_PIN) == LOW ? HIGH : LOW);
  if (Serial.available) {          // laisse le côté PC nous envoyer des caractères
    char c = Serial.read;
    Serial.print('got:'); Serial.println(c);
  }
  delay(20);
}

Then open the IDE's serial monitor (9600 baud) on the coprocessor's port to see got:x displayed when you type.

Expected Verification

Pressing the button → LED on; releasing → LED off. The x86 PC's serial monitor displays got:a for each character typed on the PC keyboard: the internal USB serial link works in both directions.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials