#include <LiquidCrystal.h>
#include "pitches.h"
#define botao1 3
#define botao2 2
LiquidCrystal lcd(13,12,11,10,9,8,7);//RS, RW, E, D4, D5, D6, D7
char letras[]={'C','D','E','F','G','A','B'};
char nota; //variável que recebe a letra que será mostrada
char historico[8]={' ',' ',' ',' ',' ',' ',' ',' '};//espaços vazios no historico
char* modo[3] = {"MANUAL","AUTO", "AUTO"}; //o asterisco é porque tem mais de uma palavra
int timmaia[] = {
NOTE_A4, 4, NOTE_C5, 4, NOTE_A4, 4, NOTE_E5, 2.75, NOTE_D5, 2, REST, 2,
NOTE_A4, 4, NOTE_C5, 4, NOTE_A4, 4, NOTE_E5, 2.75, NOTE_D5, 2, REST, 4,
NOTE_A4, 4, NOTE_C5, 4, NOTE_A4, 4, NOTE_E5, 1, REST, 1, REST, 1.5,
NOTE_A4, 4, NOTE_C5, 4, NOTE_A4, 4, NOTE_E5, 2.75, NOTE_D5, 2, REST, 2,
NOTE_A4, 4, NOTE_C5, 4, NOTE_A4, 4, NOTE_E5, 2.75, NOTE_D5, 2, REST, 4,
NOTE_A4, 4, NOTE_C5, 4, NOTE_A4, 4, NOTE_E5, 1
};
int luizgonzaga[] = {
NOTE_G4,8, NOTE_A4,8, NOTE_B4,4, NOTE_D5,4, NOTE_D5,4, NOTE_B4,4,
NOTE_C5,4, NOTE_C5,2, NOTE_G4,8, NOTE_A4,8,
NOTE_B4,4, NOTE_D5,4, NOTE_D5,4, NOTE_C5,4,
NOTE_B4,2, REST,8, NOTE_G4,8, NOTE_G4,8, NOTE_A4,8,
NOTE_B4,4, NOTE_D5,4, REST,8, NOTE_D5,8, NOTE_C5,8, NOTE_B4,8,
NOTE_G4,4, NOTE_C5,4, REST,8, NOTE_C5,8, NOTE_B4,8, NOTE_A4,8,
NOTE_A4,4, NOTE_B4,4, REST,8, NOTE_B4,8, NOTE_A4,8, NOTE_G4,8,
NOTE_G4,2, REST,8, NOTE_G4,8, NOTE_G4,8, NOTE_A4,8,
NOTE_B4,4, NOTE_D5,4, REST,8, NOTE_D5,8, NOTE_C5,8, NOTE_B4,8,
NOTE_G4,4, NOTE_C5,4, REST,8, NOTE_C5,8, NOTE_B4,8, NOTE_A4,8,
NOTE_A4,4, NOTE_B4,4, REST,8, NOTE_B4,8, NOTE_A4,8, NOTE_G4,8,
NOTE_G4,4, NOTE_F5,8, NOTE_D5,8, NOTE_E5,8, NOTE_C5,8, NOTE_D5,8, NOTE_B4,8,
NOTE_C5,8, NOTE_A4,8, NOTE_B4,8, NOTE_G4,8, NOTE_A4,8, NOTE_G4,8, NOTE_E4,8, NOTE_G4,8,
NOTE_G4,4, NOTE_F5,8, NOTE_D5,8, NOTE_E5,8, NOTE_C5,8, NOTE_D5,8, NOTE_B4,8,
NOTE_C5,8, NOTE_A4,8, NOTE_B4,8, NOTE_G4,8, NOTE_A4,8, NOTE_G4,8, NOTE_E4,8, NOTE_G4,8,
NOTE_G4,-2, REST,4
};
int pinos[]={A0,A1,A2,A3,A4,A5,4}; //botoes das notas
int freq[]={262, 294, 330, 349, 392, 440, 495}; //C,D,E,F,G,A,B
int cont = 0;
int buzzer = 5; //memoria do pino que envia o sinal/PWM Buzzer
int tempo = 80;
int tempo1 = 120;
int notes = sizeof(timmaia) / sizeof(timmaia[0]) / 2;
int notes1 = sizeof(luizgonzaga) / sizeof(luizgonzaga[0]) / 2;
int wholenote = (60000 * 2) / tempo;
int wholenote1 = (60000 * 4) / tempo1;
int divider = 0, noteDuration = 0;
int divider1 = 0, noteDuration1 = 0;
void setup() {
for (int cont = 0; cont<=6; cont++) {
pinMode(pinos[cont], INPUT);
}
pinMode(botao1, INPUT);
pinMode(botao2, INPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
lcd.begin(16,2);
lcd.clear();
delay(100);
}
void loop() {
if (digitalRead(botao1) == 1) {
noTone(buzzer);
//reinicialização do histórico
for (cont = 0; cont <=7; cont++) {
historico[cont]= ' ';
}
Serial.println(modo[1]);
//Print AUTO no lcd
lcd.clear();
lcd.setCursor(0,0);
lcd.print(modo[1]);
for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {
// calculates the duration of each note
divider = timmaia[thisNote + 1];
noteDuration = (wholenote) / divider;
// we only play the note for 90% of the duration, leaving 10% as a pause
tone(buzzer, timmaia[thisNote], noteDuration * 0.9);
// Wait for the specief duration before playing the next note.
delay(noteDuration);
// stop the waveform generation before the next note.
noTone(buzzer);
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print(modo[0]);
}
if (digitalRead(botao2) == 1) {
noTone(buzzer);
//reinicialização do histórico
for (cont = 0; cont <=7; cont++) {
historico[cont]= ' ';
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print(modo[2]);
Serial.println(modo[2]);
for (int thisNote1 = 0; thisNote1 < notes1 * 2; thisNote1 = thisNote1 + 2) {
// calculates the duration of each note
divider1 = luizgonzaga[thisNote1 + 1];
if (divider1 > 0) {
// regular note, just proceed
noteDuration1 = (wholenote1) / divider1;
} else if (divider1 < 0) {
// dotted notes are represented with negative durations!!
noteDuration1 = (wholenote1) / abs(divider1);
noteDuration1 *= 1.5; // increases the duration in half for dotted notes
}
// we only play the note for 90% of the duration, leaving 10% as a pause
tone(buzzer, luizgonzaga[thisNote1], noteDuration1 * 0.9);
// Wait for the specief duration before playing the next note.
delay(noteDuration1);
// stop the waveform generation before the next note.
noTone(buzzer);
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print(modo[0]);
}
for (int cont = 0; cont<=6; cont++) {
//executa se a leitura do pino for HIGH
if (digitalRead(pinos[cont])==HIGH) {
//noTone(buzzer);
nota = letras[cont];
tone(buzzer, freq[cont],500);
for (cont = 0; cont <=6; cont++) {
historico[7-cont]= historico[6-cont];
} //Todas as notas do histórico pulam para a direita
historico[0]=nota; //nota nova entra na esquerda
//print do modo no monitor e no lcd
Serial.println(modo[0]);
lcd.setCursor(0, 0);
lcd.print(modo[0]);
//Faz o print do hitorico
for(int i=0; i <=7; i++) {
//print no monitor serial
Serial.print(historico[i]);
if (i != 7) {
Serial.print(" ");
}
else {
Serial.println(" ");
}
//print no lcd
lcd.setCursor((2*i), 1);
lcd.print(historico[i]);
}
delay(200);
}
}
}