#include // capacitive function library to create capacitive sensors // pin 4 sends signal to pins 2 and 3 where the latter pins listen for the signal from pin 4 CapacitiveSensor pitchAntenna = CapacitiveSensor(4,2); CapacitiveSensor volAntenna = CapacitiveSensor(4,3); // variables to store smoothed raw capacitive values float smoothPitch = 500; float smoothVol = 0; void setup() { pinMode(8, OUTPUT); // pitch sound output - sends sound through 2 step RC filter to "TIP" of audio breakout board pinMode(9, OUTPUT); // LED "volume" TCCR1B = (TCCR1B & 0b11111000) | 0x01; // pwm code to prevent LED flicker - this I don't quite understand but I read about it to smooth out the flicker of the LED through the 25W amp (?) ... yes i wish i had more for you } void loop() { // variables where raw capacitive values are stored - 30 is kind of how many samples the Arduino takes to determine where your hand is long rawPitch = pitchAntenna.capacitiveSensor(30); long rawVol = volAntenna.capacitiveSensor(30); // if hand is near pitch textile, exceeding the raw capacitive value of 50 if (rawPitch > 50) { // you can change 50 to a lower number if you want to activate sound from farther away // pitch section - smooth pitch arduino can process 90% of old position with 10% of new position smoothPitch = (smoothPitch * 0.95) + (rawPitch * 0.05); int noteFreq = map(smoothPitch, 50, 1500, 450, 1600); // map functions takes the variable value and allows sensitivity between 50 and 1500 for a frequency between 450Hz and 1600Hz float v = sin(millis() * 0.004) * 10; // for vibrato - change 0.004 to change vibrato tone(8, noteFreq + v); // smoothing the volume (the LED) smoothVol = (smoothVol * 0.85) + (rawVol * 0.15); // as hand approaches, LED gets brighter at pin 9 which makes volume louder - LED + photoresistor together prevents noise from interrupting pitch signal int brightness = map(smoothVol, 50, 1200, 0, 255); analogWrite(9, constrain(brightness, 0, 255)); } else { noTone(8); analogWrite(9, 0); // no light means no sound } }