use of mp3 engine and play a randomly choosen audiofile, 1 out of 10.

I learned a lot inside thise project. Now i got the last problem to solve.

Best way to explain is in the codedescriptions.
Code descriptions with "???" at the end are the open questions. just two small questions.

const int ringerPin = A0;
//const int offhook = A4;
const int onhook = A5;
double beginRing = -40000;

void setup(){
pinMode(ringerPin, OUTPUT);
//pinMode(offhook, INPUT);
pinMode(onhook, INPUT);
randomSeed(analogRead(0)); // this starts Arduino's random number generator
}

int randCall = random(60000, 3600000); // generate a random number between 1 min and 60 min

//ring every 1 to 60 minutes if the phone is down (onhook, arduino gnd and digitalpin connected) and dont ring if the phone is picked up (no onhook)
void loop()
{
if (digitalRead(onhook) == HIGH){
delay (randCall);
beginRing = Time.elapsedTime;
while(Time.elapsedTime - beginRing <= 30000 && digitalRead(onhook) == HIGH){
//turn audio off
for(int x = 0; x < 15; x++){
digitalWrite(ringerPin, HIGH); // turn the solenoid on (HIGH is the voltage level)
delay(50); // wait for 50 msec
digitalWrite(ringerPin, LOW); // turn the solenoid off by making the voltage LOW
delay(80); // wait for 80 msec
}
delay(2500);
}
}
if(Time.elapsedTime - beginRing <= 30000){
//play one randomly choosen audiofile out of 10
}
}

int randCall = random(60000, 3600000); // generate a random number between 1 min and 60 min

How big can a signed int be ?

http://arduino.cc/en/Reference/Int

2^31
maximal
?????

MICyborg:
2^31
maximal
?????

Which Arduino board are you using ?

lily pad mp3

code is now looking like this but its still not working and i cant find a anser.

/*
#include <SPI.h> // To talk to the SD card and MP3 chip
#include <SdFat.h> // SD card file system
#include <SFEMP3Shield.h> // MP3 decoder chip
*/

//name the pins, elapsed time and output. pin1 = A0, pin2 = A4, pin3 = A5, pin4=1, pin5 = 0
const int ringerPin = A0;
//const int offhook = A4;
const int onhook = A4;
unsigned long beginRing;
//double beginRing = -40000;

/*
const int EN_GPIO1 = A2; // Amp enable + MIDI/MP3 mode select
const int SD_CS = 9; // Chip Select for SD card

// Create library objects:

SFEMP3Shield MP3player;
SdFat sd;

// Set debugging = true if you'd like status messages sent
// to the serial port. Note that this will take over trigger
// inputs 4 and 5. (You can leave triggers connected to 4 and 5
// and still use the serial port, as long as you're careful to
// NOT ground the triggers while you're using the serial port).

boolean debugging = false;

// Set interrupt = false if you would like a triggered file to
// play all the way to the end. If this is set to true, new
// triggers will stop the playing file and start a new one.

boolean interrupt = true;

// Set interruptself = true if you want the above rule to also
// apply to the same trigger. In other words, if interrupt = true
// and interruptself = false, subsequent triggers on the same
// file will NOT start the file over. However, a different trigger
// WILL stop the original file and start a new one.

boolean interruptself = false;
*/

void setup(){
pinMode(ringerPin, OUTPUT);
//pinMode(offhook, INPUT);
pinMode(onhook, INPUT);
randomSeed(analogRead(0)); // this starts Arduino's random number generator
}

int randCall = random(20200, 100000); // generate a random number between 1 min and 60 =3600000ms min

//ring every 1 to 60 minutes if the phone is down (onhook, arduino gnd and digitalpin connected
//and dont ring if the phone is picked up (no onhook)

void loop()
{
if (digitalRead(onhook) == HIGH){
//timerTime = millis();
delay (randCall);
beginRing = millis();
//elapsedTime = beginRingtimerTime
while(beginRing < beginRing + 20000 && digitalRead(onhook) == HIGH){
//turn audio off
for(int x = 0; x < 15; x++){
digitalWrite(ringerPin, HIGH); // turn the solenoid on (HIGH is the voltage level)
delay(50); // wait for 50 msec
digitalWrite(ringerPin, LOW); // turn the solenoid off by making the voltage LOW
delay(80); // wait for 80 msec
}
delay(2500);
}
}
if(beginRing < beginRing + 20000){
//play one randomly choosen audiofile out of 10
}
}

lily pad mp3

Did you read http://http://arduino.cc/en/Reference/Int ?
To quote from it

On the Arduino Uno (and other ATMega based boards) an int stores a 16-bit (2-byte) value. This yields a range of -32,768 to 32,767 (minimum value of -2^15 and a maximum value of (2^15) - 1).

So, what will happen when this line of code is executed I wonder ?

int randCall = random(20200, 100000); // generate a random number between 1 min and 60 =3600000ms min

However, as you have not said what happens when you run the program compared to what should happen we are all working in the dark here.

what should happen ? the numbers are inside that range or am i wrong?

this is a art project. a phone that rings in a random time.
the ringing process is inside the for loop that should run for 30 seconds and only if the phone is down. if the 30 sec. are over or the phone is taken off the hook it should play a mp3.

i got a lot of code implemented now but i cant control the rining process as i want to.

New code with mp3 functionality:

#include <SPI.h> // To talk to the SD card and MP3 chip
#include <SdFat.h> // SD card file system
#include <SdFatUtil.h>
#include <SFEMP3Shield.h> // MP3 decoder chip

//name the pins, elapsed time and output. pin1 = A0, pin2 = A4, pin3 = A5, pin4=1, pin5 = 0
const int ringerPin = A0;
//const int offhook = A4;
const int onhook = A4;
unsigned long beginRing;
//double beginRing = -40000;

//const int EN_GPIO1 = A2; // Amp enable + MIDI/MP3 mode select
//const int SD_CS = 9; // Chip Select for SD card

// Create library objects:

SFEMP3Shield MP3player;
SdFat sd;

void setup(){
pinMode(ringerPin, OUTPUT);
pinMode(onhook, INPUT);
randomSeed(analogRead(0)); // this starts Arduino's random number generator

//start the shield
sd.begin(SD_SEL, SPI_HALF_SPEED);
MP3player.begin();
}

int randCall = random(20200, 100000); // generate a random number between 1 min and 60 =3600000ms min

//ring every 1 to 60 minutes if the phone is down (onhook, arduino gnd and digitalpin connected
//and dont ring if the phone is picked up (no onhook)

void loop()
{
if (digitalRead(onhook) == HIGH){
//timerTime = millis();
delay (randCall);
beginRing = millis();
//elapsedTime = beginRingtimerTime
while(beginRing < beginRing + 20000 && digitalRead(onhook) == HIGH){
//turn audio off
for(int x = 0; x < 15; x++){
digitalWrite(ringerPin, HIGH); // turn the solenoid on (HIGH is the voltage level)
delay(50); // wait for 50 msec
digitalWrite(ringerPin, LOW); // turn the solenoid off by making the voltage LOW
delay(80); // wait for 80 msec
}
delay(2500);
}
}
if(beginRing < beginRing + 20000){
MP3player.playTrack(1);
//play one randomly choosen audiofile out of 10
}
}

i tryed so much different stuff. this seems to be the easyest way but i cant make it workin.
:frowning:

what should happen ? the numbers are inside that range or am i wrong?

You are attempting to create a random number between 20200 and 100000-1 and put into into a variable that can hold a value between -32,768 and 32,767. Does that seem reasonable ? At the very least the number will be negative a lot of the time.