#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 SO 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) == LOW) { tocar_nota(DO); }
if (digitalRead(Boton2) == LOW) { tocar_nota(RE); }
if (digitalRead(Boton3) == LOW) { tocar_nota(MI); }
if (digitalRead(Boton4) == LOW) { tocar_nota(FA); }
if (digitalRead(Boton5) == LOW) { tocar_nota(SO); }
if (digitalRead(Boton6) == LOW) { tocar_nota(LA); }
if (digitalRead(Boton7) == LOW) { tocar_nota(SI); }
if (digitalRead(Boton8) == LOW) { tocar_nota(DOAGUDO); }
}
void tocar_nota(int frecuencia) {
float tiempo=(500000.0/(float)frecuencia);
tiempo =cell(tiempo);
digitalWrite(parlante, HIGH);
delayMicroseconds((int)tiempo);
digitalWrite(parlante, LOW);
delayMicroseconds((int)tiempo);
}