Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int notes[] = {262,294,330,349};
- const int buttonRead = A0;
- const int piezo = 8;
- void setup()
- {
- Serial.begin(9600);
- }
- void loop()
- {
- int keyVal = analogRead(buttonRead);
- Serial.println(keyVal);
- if (keyVal >= 1020 && keyVal <= 1023)
- {
- tone(piezo, notes[0]);
- }
- else if (keyVal >= 990 && keyVal <= 1010)
- {
- tone(piezo,notes[1]);
- }
- else if(keyVal >= 505 && keyVal <= 515)
- {
- tone(piezo,notes[2]);
- }
- else if(keyVal >= 5 && keyVal <= 10)
- {
- tone(piezo,notes[3]);
- }
- else
- {
- noTone(piezo);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment