0% found this document useful (0 votes)
13 views1 page

Arduino Tone Generator Code Example

Uploaded by

sagityan13
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

Arduino Tone Generator Code Example

Uploaded by

sagityan13
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

void setup()

{
pinMode(2, INPUT);
pinMode(9, OUTPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
pinMode(8, INPUT);
}

void loop()
{
if (digitalRead(2) == HIGH) {
tone(9, 262, 25); // play tone 48 (C4 = 262 Hz)
}
if (digitalRead(3) == HIGH) {
tone(9, 294, 25); // play tone 50 (D4 = 294 Hz)
}
if (digitalRead(4) == HIGH) {
tone(9, 330, 25); // play tone 52 (E4 = 330 Hz)
}
if (digitalRead(5) == HIGH) {
tone(9, 349, 25); // play tone 53 (F4 = 349 Hz)
}
if (digitalRead(6) == HIGH) {
tone(9, 392, 25); // play tone 55 (G4 = 392 Hz)
}
if (digitalRead(7) == HIGH) {
tone(9, 440, 25); // play tone 57 (A4 = 440 Hz)
}
if (digitalRead(8) == HIGH) {
tone(9, 2093, 25); // play tone 84 (C7 = 2093 Hz)
}
delay(10); // Delay a little bit to improve simulation performancode

You might also like