#include <LiquidCrystal.h>
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
#define falador 2
const uint8_t botoes [] = {13, 12, 11, 10, 9, 8, 7, 6};
const int notas [] = {1047, 1175, 1319, 1760, 2093, 1397, 1568, 1976};
const int numTones = sizeof(botoes) / sizeof(botoes[0]);
void setup() {
// put your setup code here, to run once:
for (uint8_t i = 0; i < numTones; i++){
pinMode (botoes[i], INPUT_PULLUP);
}
pinMode (falador, OUTPUT);
lcd.begin(16,2);
lcd.print("Press a button!");
lcd.setCursor(6, 1);
lcd.print("->");
tone(falador, 1047);
delay(100);
noTone(falador);
delay(50);
tone(falador, 1397);
delay(100);
noTone(falador);
delay(50);
tone(falador, 1760);
delay(100);
noTone(falador);
}
void loop() {
// put your main code here, to run repeatedly:
int tom = 0;
for (uint8_t i = 0; i < numTones; i++) {
if (digitalRead(botoes[i]) == LOW) {
tom = notas[i];
}
}
if (digitalRead(13) == LOW){
lcd.setCursor(8, 1);
lcd.print("Do ");
}
if (digitalRead(12) == LOW){
lcd.setCursor(8, 1);
lcd.print("Re ");
}
if (digitalRead(11) == LOW){
lcd.setCursor(8, 1);
lcd.print("Mi ");
}
if (digitalRead(10) == LOW){
lcd.setCursor(8, 1);
lcd.print("La ");
}
if (digitalRead(9) == LOW){
lcd.setCursor(8, 1);
lcd.print("Do ");
}
if (digitalRead(8) == LOW){
lcd.setCursor(8, 1);
lcd.print("Fa ");
}
if (digitalRead(7) == LOW){
lcd.setCursor(8, 1);
lcd.print("Sol");
}
if (digitalRead(6) == LOW){
lcd.setCursor(8, 1);
lcd.print("Si ");
}
if (tom){
tone(falador, tom);
}
else{
noTone(falador);
}
}