byte listaN[7]={15,16,17,18,19,21,22};
int nota[7]={1,3,5,6,8,10,12};
class Teclado {
byte pin_buzzer, pin_tecla, octava;
int frec(byte o, byte n){
return (440*exp((o-4+((n-10)/12.))*log(2)));
}
public:
Teclado(byte boton, byte buzzer){
byte cnotas = boton + 7;
octava = 5;
pin_buzzer = buzzer;
pin_tecla = boton;
for( ; boton<cnotas ; boton++){
pinMode(boton, INPUT_PULLUP);
}
pinMode(pin_buzzer, OUTPUT);
}
void teclas(void){
for(byte t=0 ; t<2; t++){
if(!digitalRead(listaN[t]){
tone(pin_buzzer,frec(octava,nota[t]));
delay(150);
}
noTone(pin_buzzer);
}
}
};
Teclado t(15,4);
void setup() {
}
void loop() {
t.teclas();
}