#define parlante 2
#define Boton1 12
#define Boton2 11
#define Boton3 10
#define Boton4 9
#define Boton5 8
#define Boton6 7
#define Boton7 6
#define Boton8 5
#define DO 261
#define RE 293
#define MI 329
#define FA 349
#define SOL 391
#define LA 440
#define SI 493
#define DOAGUDO 523
void setup() {
pinMode(parlante, OUTPUT);
pinMode(Boton1, INPUT_PULLUP);
pinMode(Boton2, INPUT_PULLUP);
pinMode(Boton3, INPUT_PULLUP);
pinMode(Boton4, INPUT_PULLUP);
pinMode(Boton5, INPUT_PULLUP);
pinMode(Boton6, INPUT_PULLUP);
pinMode(Boton7, INPUT_PULLUP);
pinMode(Boton8, INPUT_PULLUP);
}
void loop() {
if(digitalRead(Boton1)==0){tocar_nota(DO);}
if(digitalRead(Boton2)==0){tocar_nota(RE);}
if(digitalRead(Boton3)==0){tocar_nota(MI);}
if(digitalRead(Boton4)==0){tocar_nota(FA);}
if(digitalRead(Boton5)==0){tocar_nota(SOL);}
if(digitalRead(Boton6)==0){tocar_nota(LA);}
if(digitalRead(Boton7)==0){tocar_nota(SI);}
if(digitalRead(Boton8)==0){tocar_nota(DOAGUDO);}
}
void tocar_nota(int frecuencia){
float tiempo = (500000.0/(float)frecuencia);
tiempo = ceil(tiempo);
digitalWrite(parlante, HIGH);
delayMicroseconds((int)tiempo);
digitalWrite(parlante, LOW);
delayMicroseconds((int)tiempo);
}