#include <CapacitiveSensor.h>
#include <Tone.h>

/*CapitiveSense Library by Paul Badger 2008*/

CapacitiveSensor   cs_2_4 = CapacitiveSensor(2,4);		// pin 2 is the sending pin, pins 4, 6, and 8 are the sensor pins
CapacitiveSensor   cs_2_6 = CapacitiveSensor(2,6);        
CapacitiveSensor   cs_2_8 = CapacitiveSensor(2,8);        

Tone notePlayer1;		// variable declared for each buzzer
Tone notePlayer2;
Tone notePlayer3;


void setup()                    
{
   Serial.begin(9600);
   
   notePlayer1.begin(10);		// buzzers are assigned to pins 10, 11, and 12
   notePlayer2.begin(11);
   notePlayer3.begin(12);
}

void loop()                    
{
    long start = millis();
    long total1 =  cs_2_4.capacitiveSensor(30);
    long total2 =  cs_2_6.capacitiveSensor(30);
    long total3 =  cs_2_8.capacitiveSensor(30);

    Serial.print(millis() - start);        // check on performance in milliseconds
    Serial.print("\t");                    // tab character for serial monitor spacing

    Serial.print(total1);                  // print sensor output 1
    Serial.print("\t");
    Serial.print(total2);                  // print sensor output 2
    Serial.print("\t");
    Serial.println(total3);                // print sensor output 3
    
    if (total1 > 500 ) {				   // if the sensed capacitance for the first tack is more than 500, then the first buzzer will play note DS3
          notePlayer1.play(NOTE_DS3);	   // notes can vary between B0 to D7 as frequency is limited to 2.4 kHz
    } else {
          notePlayer1.stop();
    } 
        
    if (total2 > 500) {
           notePlayer2.play(NOTE_B3);
    } else {
           notePlayer2.stop();
    }
    
    if (total3 > 500) {
           notePlayer3.play(NOTE_F3);
    } else {
           notePlayer3.stop();
    }
    
    delay(0);                             // arbitrary delay to limit data to serial port 
}