i'm a artist from Amsterdam and I made an interactive sound installation.
I connected a home depot movement sensor, a flash player, a tl-lamp and a robot.
Here is a small movie to see the berta version of the installation working:
The dancing white man
I assemble the Wave Shield kit and got the Arduino board up & running conected with a the Maxbotics EZ1 http://www.maxbotix.com which has an analog signal output and a EZtronics – Your Phidgets and Atlas Scientific dealer based in Europe dual relay board.
What I would like is the following:
if the sensor detects movement:
-the tl-lights go on.
-the robot gets its power and start moving.
-the waveshield starts one of the wav sounds on the sd card..
[so it remembered the song and the exact point where it ended the last time.[ out of the differend songs on the sd-card]]
-after +- 7 seconds everything above stops. [the relay closes and the wavecard pauses]
then it wait for +- 78 seconds andstarts checking the "if sensor detects movement" again....
I 'm new to programming but i found 3 scrips that I think I have to combine:
thanks to Audio Shield for Arduino
the Digital audio player sketch
#include <AF_Wave.h>
#include <avr/pgmspace.h>
#include "util.h"
#include "wave.h"
AF_Wave card;
File f;
Wavefile wave; // only one!
#define redled 9
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Wave test!");
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(redled, OUTPUT);
if (!card.init_card()) {
putstring_nl("Card init. failed!"); return;
}
if (!card.open_partition()) {
putstring_nl("No partition!"); return;
}
if (!card.open_filesys()) {
putstring_nl("Couldn't open filesys"); return;
}
if (!card.open_rootdir()) {
putstring_nl("Couldn't open dir"); return;
}
putstring_nl("Files found:");
ls();
}
void ls() {
char name[13];
int ret;
card.reset_dir();
putstring_nl("Files found:");
while (1) {
ret = card.get_next_name_in_dir(name);
if (!ret) {
card.reset_dir();
return;
}
Serial.println(name);
}
}
uint8_t tracknum = 0;
void loop() {
uint8_t i, r;
char c, name[15];
card.reset_dir();
// scroll through the files in the directory
for (i=0; i<tracknum+1; i++) {
r = card.get_next_name_in_dir(name);
if (!r) {
// ran out of tracks! start over
tracknum = 0;
return;
}
}
putstring("\n\rPlaying "); Serial.print(name);
// reset the directory so we can find the file
card.reset_dir();
playcomplete(name);
tracknum++;
}
void playcomplete(char *name) {
playfile(name);
while (wave.isplaying) {
putstring(".");
delay(100);
}
card.close_file(f);
}
void playfile(char *name) {
f = card.open_file(name);
if (!f) {
putstring_nl(" Couldn't open file"); return;
}
if (!wave.create(f)) {
putstring_nl(" Not a valid WAV"); return;
}
// ok time to play!
wave.play();
}
the sensor read sketch
//Output
int statusLed = 13;
//intput
int ez1Analog = 0;
void setup() {
pinMode(statusLed,OUTPUT);statusLed
pinMode(ez1Analog,INPUT);
beginSerial(9600);
}
void loop() {
int val = analogRead(ez1Analog);
if (val > 0) {
// The Maxbotix reports 512 steps of information on AN
// but we read that as 1024. Each step is 1", so we need
// to divide by 2 to get the correct rough range in inches.
//
// this value should also be calibrated for your particular
// sensor and enclosure
val = val* 2.24;
Serial.println(val); // cm
}
blinkLed(statusLed,val);
}
void blinkLed(int pin, int ms) {
digitalWrite(pin,LOW); // turn it off it was on
digitalWrite(pin,HIGH);
delay(ms);
digitalWrite(pin,LOW);
delay(ms);
}
and
Saving & restoring the play position
If, say, you want to know where along in the wave file you are, that information is also available in wave. in wave.getSize() (the number of bytes in the entire wave) and wave.remainingBytesInChunk (how many bytes are left to play)
You can set the current place to play from using wave.seek(), the Arduino will immediately start to fastforward to that location. For example, wave.seek(0) will take you to the beginning, wave.seek(wave.getSize()/2) will take you to the middle of the file.
I hope that someone can help me further cause for me its too difficult.
greetings
Leonard