Module 18 // Audio Synthesis
Electronic Piano
Integrates tactile switch matrix logic gates to trigger musical frequency generation when keypress values narrow down. The Arduino converts button inputs into piano notes through a piezoelectric speaker.
Piano Key Mapping
| Input Key | Vector Mapping | Target Uno Pin |
|---|---|---|
| DO Button | ====> | Digital Pin 2 |
| RE Button | ====> | Digital Pin 3 |
| MI Button | ====> | Digital Pin 4 |
| Piezo Speaker | ====> | Digital Pin 8 |
Audio Firmware
const int buzzer = 8;
void setup()
{
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
}
void loop()
{
if(digitalRead(2)==LOW)
{
tone(buzzer,262);
}
else if(digitalRead(3)==LOW)
{
tone(buzzer,294);
}
else if(digitalRead(4)==LOW)
{
tone(buzzer,330);
}
else
{
noTone(buzzer);
}
}