The Code we Used:
For Arduino

int BUTTON_A = 2; // Connect button A to pin 2 on the Arduino

int BUTTON_B = 3; // Connect button B to pin 3 on the Arduino

int BUTTON_C = 6; // Connect button C to pin 4 on the Arduino

int BUTTON_D = 5;

int BUTTON_E = 4;

int BUTTON_Q = 8;

int LED_PINA = 11; // For the leds

int LED_PINB = 17;

int LED_PINC = 10;

int LED_PIND = 7;

int LED_PINE = 18;

// Add more button pins as needed


int PIEZO = 12; // Buzzer or speaker pin

void setup() {

Serial.begin(9600); // Initialize serial communication at 9600 baud

pinMode(BUTTON_A, INPUT_PULLUP); // Set button A pin as input with internal pull-up resistor

pinMode(BUTTON_B, INPUT_PULLUP); // Set more pin buttons as input with internal pull-up resistor if needed

// Add more pins as needed


pinMode(LED_PINA, OUTPUT); // for the leds

pinMode(LED_PINB OUTPUT);

// Add more leds as needed


//Initialize piezo pin

pinMode(PIEZO, OUTPUT);

}


void loop() {

// Read the state of button A

if (digitalRead(BUTTON_A) == LOW) {

playPianoNote(12, 230); // Play A note (440 Hz)

digitalWrite(LED_PINA, HIGH);

} else {

digitalWrite(LED_PINA, LOW);

}


// Read the state of button B

if (digitalRead(BUTTON_B) == LOW) {

playPianoNote(12, 330); // Play B note (494 Hz)

digitalWrite(LED_PINB, HIGH);

} else {

digitalWrite(LED_PINB, LOW);

}

// Add more as needed


// Adding auto music

if (digitalRead(BUTTON_Q) == LOW) {

midi(); // Call your midi function when the button is pressed

}

// Add more buttons and notes as needed

}


void midi() {

digitalWrite(LED_PIND, HIGH); // For the lights to bright when it plays


tone(PIEZO, 146, 706.188118812); // Custom music

delay(784.653465347);

delay(264.851485149);

digitalWrite(LED_PIND, LOW);


// Add more tones as needed

}


void playPianoNote(int PIEZO, int frequency) {

tone(PIEZO, frequency, 100); // Play the specified note for 100 ms

delay(100); // Delay to ensure the note is heard

noTone(PIEZO); // Stop the tone

}

Much clear here!:

Code