could somebody help me with the code
hello,
this first arduino code. parts wrote, others copied parts of posted online.
i trying add command inside void loop() , have suspicion sequence of commands not right , can't figure out how should done.
there 3 pir sensors installed in room. when either 1 of them detects presence of person, playback of 2 soundtracks start. 1 soundtrack on cd player, on rmp3 shield.
the soundtracks 1 hr long thought add physical button send 'stop' rmp3.stop(); command shield have playback reset option , don't understand if code resetbutton wrong or whether put in wrong order.
could please`look @ code tell me what's wrong. appreciate it.
i hope explanations clear, code below.
thank much.
m.
this first arduino code. parts wrote, others copied parts of posted online.

i trying add command inside void loop() , have suspicion sequence of commands not right , can't figure out how should done.
there 3 pir sensors installed in room. when either 1 of them detects presence of person, playback of 2 soundtracks start. 1 soundtrack on cd player, on rmp3 shield.
the soundtracks 1 hr long thought add physical button send 'stop' rmp3.stop(); command shield have playback reset option , don't understand if code resetbutton wrong or whether put in wrong order.
could please`look @ code tell me what's wrong. appreciate it.
i hope explanations clear, code below.
thank much.
m.
code: [select]
#include <newsoftserial.h>
#include <roguesd.h>
#include <roguemp3.h>
//sketch start payback of soundtracks on cd player , mp3 shield
//when 1 of 3 pir's reads high
//may 1, 2010
//mikhail iliatov
//parts copied code mgehring , tj on arduino.cc
#define cd 10
#define pir1 2
#define pir2 3
#define pir3 4
#define resetbutton 8
newsoftserial rmp3_serial(6, 7);
roguemp3 rmp3(rmp3_serial);
int duration=20;
//temporary number, changed actual length of soundtrack
//(prob. 3923586 + time start cd (10 sec.) => 3933586 milisec or 3933.586 s ~= 3934 s)
void setup(){
serial.begin(9600);
rmp3_serial.begin(9600);
pinmode(cd, output);
pinmode(pir1, input);
pinmode(pir2, input);
pinmode(pir3, input);
pinmode(resetbutton, input);
//this resetbutton trying incoprporate
//so can stop mp3 in middle of playback if necessary
digitalwrite(pir1, low);
digitalwrite(pir2, low);
digitalwrite(pir3, low);
digitalwrite(resetbutton, low); //check this
rmp3.sync();
//don't know function in rmp3 library sample code
int calibrationtime = 30; //do need use calibration, check parallax
// int song="/nhd050708.mp3"; how define songname?
//calibrate sensor
serial.print("calibrating sensor ");
for(int = 0; < calibrationtime; i++){
serial.print(".");
delay(1000);
}
serial.println(" done");
serial.println("sensor active");
delay(50);
//insert stop command cd here?
}
void loop(){
//this code doesn't work , have no idea why or paste it!
if (digitalread(resetbutton) == high){
digitalwrite(13, high); //to turn led on know reset button works
rmp3.stop(); //to stop rmp3
}
if ((digitalread (pir1) == low) || (digitalread (pir2) == low) || (digitalread (pir3) == low)){
digitalwrite (cd, low);
//insert stop command cd here make sure nothing triggered while calibrating sensors
}
else {
digitalwrite (cd, high);
delay(500);
digitalwrite (cd, low);
delay(5000); //time cd player start
rmp3.playfile("/tinfou2_final.mp3");
serial.println("now playing"); //figure how print status mp3?
delay_secs(duration);
// pause program while soundtrack playing duration == length of sountrack
serial.println("stopped");
}
}
void delay_secs( int secs ) // delays 'secs' seconds
{
int i;
for(i=0; i<secs; i++)
delay(1000);
}
/*think adding button stop playback on both cd , mp3 @ time
*/
i suggest implementing application "finite state machine".
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > could somebody help me with the code
arduino
Comments
Post a Comment