I almost finalized my first prototype of LED harp, it works with 2 infrared LED emitting then receiving the infrared reflected by the finger above.
When I place my finger above the LEDs, the music will start playing correctly but the sound is twitching at starts, I wonder if it is a boucing problem or a streaming one. What do you think ?
If it is a bouncing problem I woudl still be in problem because it is not a binary button state but a analogRead.
I don't have that kind of twitching issue with the player_simple example code.
Here is my code :
Code: Select all
// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
// pin used by the shield
#define RESET -1 // VS1053 reset pin (unused)
#define CS 7 // VS1053 chip select pin (output)
#define DCS 6 // VS1053 Data/command select pin (output)
#define CARDCS 4 // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3 // VS1053 Data request, ideally an Interrupt pin
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(RESET, CS, DCS, DREQ, CARDCS);
// DEBUT DU CODE LUMINARPE
const int cordeMax = 5; // total number of chords
int sensorPin[cordeMax]; // infrared measured
const int analogPin[] = {A8, A9, A10, A11, A12};
const int potentioPin = A7;
const int ledPin = 13; // for debugging
const int irPin = 22; // infrared emitter alimentation
char *files[5]={"track001.mp3", "track002.mp3", "track003.mp3", "track004.mp3", "track005.mp3"};
int corde = 0; // chord id
int potentioValue;
int ambientIR; // infrared measure with the IR emitter OFF
int activeIR; // infrared measure with the IR emitter ON
int ledState[cordeMax]; // to know which chord is activated
float sensorTemp[cordeMax]; // difference between ambientIR and activeIR
void setup(){
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(irPin, OUTPUT); // IR emitter LED on digital pin
for(int i = 0 ; i < cordeMax ; i++){
ledState[i] = 0; // Initialize all ledState to 0
sensorTemp[i] = 0; // Initialize all sensorTemp to 0
sensorPin[i] = analogPin[i];
}
if (! musicPlayer.begin()) { // initialise the music player
Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
while (1);
}
SD.begin(CARDCS); // initialise the SD card
// Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.setVolume(20,20);
// If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
// audio playing
musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT); // DREQ int
musicPlayer.startPlayingFile(files[0]); //OK GO
}
void loop(){
if (corde == cordeMax) corde = 0;
delay(10); //if I don't do that the harp bugs
digitalWrite(irPin,LOW); // turning the IR LEDs off to read the IR coming from the ambient
delay(1); // minimum delay necessary to read values
ambientIR = analogRead(sensorPin[corde]); // storing IR coming from the ambient in the middle of the harpe
digitalWrite(irPin,HIGH); // turning the IR LEDs on to read the IR coming from the obstacle
delay(1); // minimum delay necessary to read values
potentioValue = analogRead(potentioPin); // the potentiometre is to change the sensitivity off the chords (if light changes for example)
activeIR = analogRead(sensorPin[corde]);
sensorTemp[corde] = activeIR - ambientIR;
if (sensorTemp[corde] > potentioValue)
{
if (ledState[corde] == 0){
ledState[corde] = 1;
// Serial.write(corde); //for later communication with computer
if(!musicPlayer.playingMusic)
{
musicPlayer.startPlayingFile(files[corde]);
delay(1);
}
}
}
else
{
if (ledState[corde] == 1){
ledState[corde] = 0;
musicPlayer.stopPlaying();
delay(1);
}
}[b][/b]
corde += 1;
}