daily pastebin goal
12%
SHARE
TWEET

Untitled

a guest Jan 20th, 2014 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Tone.h>
  2. int notes[] = {262, 294, 330, 349};
  3.  
  4. void setup() {
  5.     //start serial communication
  6.   Serial.begin(9600);
  7. }
  8.  
  9. void loop() {
  10.   // create a local variable to hold the input on pin A0
  11.   int keyVal = analogRead(A0);
  12.   // send the value from A0 to the Serial Monitor
  13.   Serial.println(keyVal);
  14.  
  15.   // play the note corresponding to each value on A0
  16.   if(keyVal == 1023){
  17.     // play the first frequency in the array on pin 8
  18.     Tone(8, notes[0]);
  19.   }
  20.   else if(keyVal >= 990 && keyVal <= 1010){
  21.     // play the second frequency in the array on pin 8
  22.     Tone(8, notes[1]);
  23.   }
  24.   else if(keyVal >= 505 && keyVal <= 515){
  25.     // play the third frequency in the array on pin 8
  26.     Tone(8, notes[2]);
  27.   }
  28.   else if(keyVal >= 5 && keyVal <= 10){
  29.     // play the fourth frequency in the array on pin 8
  30.     Tone(8, notes[3]);
  31.   }
  32.   else{
  33.     // if the value is out of range, play no tone
  34.     noTone(8);
  35.   }
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top