Wednesday, November 25, 2009

Wall as a Boombox

We were able to get both the record and play functions of the RadioShack recording module to work, controlled by the Arduino board. We have two foil sensors - a 'play' and 'record' button - which we will refine further in the final installation, either with conductive paint or foil stickers. The Arduino board is portable and could be installed briefly with the stickers or paint - when it's removed, and the paint or stickers could potentially remain, leaving a trace of the interaction.

The speaker is used as the microphone also, and it's very quiet. We're considering whether we want to upgrade and/or separate these components.

We simplified our code a lot this week:
#include
CapSense cs_4_2 = CapSense(4,2); // PLAY FOIL CONNECTED TO PINS 4 and 2, 2 is sensor pin
CapSense cs_5_3 = CapSense(5,3); // REC FOIL CONNECTED TO PINS 5 and 3, 3 is sensor pin
int recPin = 12;
int playPin = 13;

long start, recLength = 1000;
float threshold = 0.35;
float playTotal, recTotal;


void setup()
{
// cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
Serial.begin(9600);
pinMode(recPin, OUTPUT);
pinMode(playPin, OUTPUT);
}

void loop()
{
// GET RAW SENSOR DATA; TUNE POTENTIOMETER/RESISTOR FOR 0-60 RANGE:
start = millis();
playTotal = (float)cs_4_2.capSense(30) / (float)60; // PLAY FOIL
recTotal = (float)cs_5_3.capSense(30) / (float)60; // REC FOIL


// DEBUG SCREEN
Serial.print("PLY: ");
Serial.print("\t");
Serial.print(playTotal);
Serial.print("REC: ");
Serial.print("\t");
Serial.println(recTotal);

// IF WITHIN THRESHOLD
if(playTotal >= threshold || recTotal >= threshold) {
// IF PLAY, PLAY
if(playTotal > recTotal) {
play(recLength);
}
// OTHERWISE, RECORD
else {
recLength = record();
}
}
}

long record() {
long startTime = millis();
while (recTotal > threshold) {
digitalWrite(recPin,HIGH);
recTotal = (float)cs_5_3.capSense(30) / (float)60; // REC FOIL
}
long endTime = millis();
digitalWrite(recPin,LOW);
Serial.print("REC - Length:\t");
Serial.println(endTime-startTime);
return endTime - startTime;
}

void play(long howLong) {
Serial.print("PLAY - Length:\t");
Serial.println(howLong);
digitalWrite(playPin,HIGH);
delay(10);
digitalWrite(playPin,LOW);
delay(howLong);
}

So, there is a 'record' foil and a 'play' foil. When you put your hand within the 'threshold' distance from the record foil, it starts recording and counts how long you kept your hand there. When you put your hand near (within the same threshold) the 'play' foil, it plays (and ignores input for the length of the recording).



Here it is in action. It's quiet, but it works!




Next steps:
Pick a site on campus, probably in Avery Hall
Build/Refine a housing for the Arduino board, including power (9V battery or wall-plug)
Design and test the stickers/conductive paint
Look into the speaker sensitivity/microphone power issue

No comments:

Post a Comment