Hoy les traemos el clásico código de Arduino «Keyboard Melody», pero con modificaciones para hacerlo funcional con 3 botones (pulsadores) y 1 buzzer.

#include «pitches.h»


const int threshold = 10;
 
int notes[] = {
  NOTE_A4NOTE_B4NOTE_C3
};


int botones[] = {
247
};


void setup() {
  for (int boton_actual = 0boton_actual < 3boton_actual++) {
    pinMode(botones[boton_actual], INPUT);
  }
}


void loop() {
  for (int boton_actual = 0boton_actual < 3boton_actual++) {
    int valor_boton = digitalRead(botones[boton_actual]);
 
    if (valor_boton == HIGH) {
      tone(8notes[boton_actual], 20);
    }
  }
}


Esquema de Conexion




Descarga el proyecto adaptado:

https://www.patreon.com/posts/keyboard-melody-139501684