Hi,
I am a total beginner but I am working on a project for school.
I am trying to create a wearable device using a accelerometer that plays sound when the wearer moves his feet, and the volume of the sound will change depending on the speed that feet are moving.
This device is meant to be used by dancers or performance artists in order to make their performance more interesting by introducing sound that reacts to their movement.
This is an overview of the prototype that I made.
~Connected with Wire~
-2 accelerometers(one for each side ideally, but I am trying to get it working with one first) (Adafruit Triple-Axis Accelerometer MMA8451)I found a sketch on adafruit that controls the volume of the wave shield with software, and tweaked it in order to use the accelerometer value.(I am only using z-axis value)
I managed to make it kinda work, but still having some problems.
The wave shield is constantly playing the sound effect(I am using wind sound) but the volume is off when there is no movement, so that it looks like the sound is not playing at all.
Whenever the wearer moves his feet, the acceleration value from the accelerometer determines the volume of the sound track and make it audible.
However, because of the code structure that I am using, there is always a ticking noise between every transition(between every delay of the code) of the volume.
I am wondering if there is a way to get rid of this noise.
Or is there a better way to approach this project?
Your advices will be really helpful!!
Below is the sketch that I am using
#include <Wire.h>
#include <WaveHC.h>
#include <WaveUtil.h>
#include <Adafruit_MMA8451.h>
#include <Adafruit_Sensor.h>
SdReader card; // This object holds the information for the card
FatVolume vol; // This holds the information for the partition on the card
FatReader root; // This holds the information for the volumes root directory
FatReader file; // This object represent the WAV file
WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time
Adafruit_MMA8451 mma = Adafruit_MMA8451();
/*
- Define macro to put error messages in flash memory
*/
#define error(msg) error_P(PSTR(msg))
//////////////////////////////////// SETUP
void setup() {
Serial.begin(9600);
// try card.init(true) if errors occur on V1.0 Wave Shield
card.init();
// enable optimize read - some cards may timeout
card.partialBlockRead(true);
vol.init(card);
root.openRoot(vol);
root.ls();
mma.begin();
mma.setRange(MMA8451_RANGE_2_G);
}
// forward declarition
void playcomplete(FatReader &file);
//////////////////////////////////// LOOP
void loop() {
uint8_t i, r;
char c, name[15];
dir_t dir;
root.rewind();
// scroll through the files in the directory
while (root.readDir(dir) > 0) {
// only play .WAV files
if (!file.open(vol, dir)){
putstring("Can't open ");
printEntryName(dir);
Serial.println();
continue;
}
putstring("\n\rPlaying ");
printEntryName(dir);
Serial.println();
playcomplete(file);
file.close();
}
}
/////////////////////////////////// HELPERS
/*
- Play files with software volume control
*/
void playcomplete(FatReader &file) {
if (!wave.create(file)) {
putstring_nl(" Not a valid WAV"); return;
}
// ok time to play!
wave.play();
while (wave.isplaying) {
putstring("Vol: ");
// DVOLUME must be nonzero in WaveHC.h to use volume.
Serial.println(wave.volume, DEC);
mma.read();
Serial.print("Z:\t"); Serial.print(mma.z);
Serial.println();
sensors_event_t event;
mma.getEvent(&event);
Serial.print("Z: \t"); Serial.print(event.acceleration.z); Serial.print("\t");
Serial.println("m/s^2 ");
delay(10);
wave.volume = 20 - event.acceleration.z;
}
}