// 
//  Piano Project
//  ECE 2360
// 

#include <LiquidCrystal.h>// include the library code
#include <pitches.h>

#define SPEAKER_PIN 7

const int buttonPins[] = {34, 32, 30, 28, 26, 24, 22};
const char* buttonNotes[] = {"C4", "D4", "E4", "F4", "G4", "A4", "B4"};
const int buttonTones[] = {
  NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4,
  NOTE_G4, NOTE_A4, NOTE_B4
};
const int numberOfButtons = sizeof(buttonPins) / sizeof(buttonPins[0]);

LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

void setup()
{
  Serial.begin(9600);  // start serial port at 9600 bps:

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);

  for (int btn = 0; btn < numberOfButtons; btn++)
  {
    pinMode(buttonPins[btn], INPUT); // make all the button pins inputs
  }

  pinMode(SPEAKER_PIN, OUTPUT);
}

void loop() {
  unsigned long currentTime = millis();

  int pitch = 0;
  for (int btn = 0; btn < numberOfButtons; btn++)
  {
    const int buttonState = digitalRead(buttonPins[btn]);
    if (buttonState == HIGH) {
      char* note = buttonNotes[btn];
      Serial.print("Pressed Button: ");
      Serial.println(note);
      printToLCD(note);
      pitch = buttonTones[btn];
    } else {

    }
  }

  if (pitch) {
    tone(SPEAKER_PIN, pitch);
  } else {
    noTone(SPEAKER_PIN);
  }
}

void printToLCD(const char* text) {
  lcd.clear();
  for (int i = 0; text[i] != '\0'; i++) {
    lcd.setCursor(i, 0);
    lcd.print(text[i]);
  }
}
$abcdeabcde151015202530354045505560fghijfghij