Hi there,
I've recently built a "fruit piano" of sorts using CapSense Library (takes capacity value in a circuit of two pins and a resistor in between, emits a tone if value exceeds threshold)
Here's about what it looks like:
The code is really very simple:
#include <CapacitiveSensor.h>
#define SND_PIN 13
int range = 700;
byte button;
int freq;
CapacitiveSensor cs_2_3 = CapacitiveSensor(2,3);
CapacitiveSensor cs_2_4 = CapacitiveSensor(2,4);
CapacitiveSensor cs_2_5 = CapacitiveSensor(2,5);
CapacitiveSensor cs_2_6 = CapacitiveSensor(2,6);
CapacitiveSensor cs_2_7 = CapacitiveSensor(2,7);
void setup()
{
Serial.begin(9600);
}
void loop()
{
long total1 = cs_2_3.capacitiveSensor(30);
long total2 = cs_2_4.capacitiveSensor(30);
long total3 = cs_2_5.capacitiveSensor(30);
long total4 = cs_2_6.capacitiveSensor(30);
long total5 = cs_2_7.capacitiveSensor(30);
button = 0;
if (total1 > range) button |= 1;
if (total2 > range) button |= 2;
if (total3 > range) button |= 3;
if (total4 > range) button |= 4;
if (total5 > range) button |= 5;
switch (button) {
case 1: freq = 523.25; break; // C
case 2: freq = 587.33; break; // D
case 3: freq = 659.26; break; // E
case 4: freq = 698.46; break; // F
case 5: freq = 783.99; break; // G
case 6: freq = 700; break; //
case 7: freq = 800; break; //
default: freq = 0;
Serial.begin(9600);
Serial.print("\t"); // tab character for debug window 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
}
freq? tone(SND_PIN, freq) : noTone(SND_PIN);
}
What I'd like to do is enhance the "piano" with custom sounds, probably by using the serial connection with the laptop, probably with processing - make a piece of software capable of reading total1, total2 etc. and play sounds accordingly, but before I delve into it, I've got a ton of questions:
-
My project is definitely not the first of its kind, someone must have already come up with a tool to play sounds from serial port code, if you have that or know where to find it, that'd save me lots of time.
-
Feasibility - it is entirely possible to do what I mean to do, right?
-
If there is no software made for my purposes already, can you give me a nod as to which functions I should use in Processing, I'm totally new to the whole thing.
Thank you.
Every little bit helps
Best regards,
Me
