[Arduino Diary #10] Piezo & Armstrong.

Here’s a demonstration of making sounds in Arduino using Piezo.


int notes[] = {262, 294, 330, 349};

void setup() {
Serial.begin(9600);
}

void loop() {
int keyVal = analogRead(A0);
Serial.println(keyVal);
if(keyVal > 1010) {
tone(8,notes[0]);
}else if(keyVal >= 990 && keyVal <= 1010) {
tone(8,notes[1]);
}else if(keyVal >= 505 && keyVal <= 515) {
tone(8,notes[2]);
}else if(keyVal >= 5 && keyVal <= 10) {
tone(8,notes[3]);
}else{
noTone(8);
}
}

The strange thing about the above code is that I couldn’t make multiple sounds at the same time by “disjointing” if-else clauses like “if, if, if, if”. If I would do that Piezo will make same strange sounds for all four buttons.

Here’s a library to create musical instrumental sounds.

Screen Shot 2014-09-22 at 9.08.49 AM

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: