Minim Sound Stops Playing After A While

edited December 7 in Arduino

So I found a sample code that I altered that reads my Arduino through the serial port and plays several different sounds that tell me to either sit, stand, or move. I've added rewind, so the sounds play more than once, but after several hours the sounds no longer play. Does that functionality time out? I added a few lines to print if the program thinks the song is playing and that all goes through fine. I would appreciate any help because I would like to not have to restart this program several times throughout the day.

import processing.serial.*;

import ddf.minim.*;


Minim minim;

AudioPlayer stand;

AudioPlayer sit;

AudioPlayer move;

AudioPlayer bitch;

AudioPlayer beep;


int lf = 10; 

String myString = null;

Serial myPort; 

int sensorValue = 0;


void setup() {


  printArray(Serial.list());


  myPort = new Serial(this, Serial.list()[0], 9600);

  myPort.clear();

  myString = myPort.readStringUntil(lf);

  myString = null;

  minim = new Minim(this);


  stand = minim.loadFile("stand.mp3"); 

  sit = minim.loadFile("sit.mp3");

  move = minim.loadFile("move.mp3");

  bitch = minim.loadFile("bitch.mp3");

  beep = minim.loadFile("beep.mp3");

}


void draw() {

  while (myPort.available() > 0) {

    myString = myPort.readStringUntil(lf);

    if (myString != null) {

      myString = myString.trim();  

      if(myString.length() > 0) {

        println(myString);      

        }

      if(myString.equals("sit")){

            println("sound");

            beep.rewind();

            sit.rewind();

            beep.play();

            delay(800);

            sit.play();

            if (sit.isPlaying() == true){

              println("sound2");

            }

        }      

      if(myString.equals("stand")){

            println("sound");

            beep.rewind();

            stand.rewind();

            beep.play();

            delay(800);

            stand.play();

            if (stand.isPlaying() == true){

              println("sound2");

            }

        }     

      if(myString.equals("move")){

            println("sound");

            beep.rewind();

            move.rewind();

            bitch.rewind();

            beep.play();

            delay(800);

            move.play();

            delay(550);

            bitch.play();

            if (bitch.isPlaying() == true){

              println("sound2");

            }

            }

          }

    }

  }

Answers

  • Please format your code. Edit your post (gear on top right side of any of your posts), select your code and hit ctrl+o. Leave an empty line above and below your block of code. Details here: https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text

    When it stops working, does it show an error? Can you describe your program a bit more? For instance, what is the input rate of your arduino? How often are you sending these messages to Processing?

    I have to say I wouldn't use delay() function in the Processing draw() at all. I bet delay could be the culprit in your program. It is a guess though...

    Kf

  • Thanks, I couldn't quite figure out how to get it to look right.

    It doesn't show an error, just stops playing any sounds. It gets input from the Arduino automatically on 20 minutes, 8 minutes, and then 2 minutes intervals (20 minutes of sitting, 8 minutes of standing, 2 minutes of moving then repeat), with the possibility of me manually progressing with a button. If I spam that button repeatedly, it will cycle through the noises and not break. It's just when it's been running for multiple hours does it stop working.

    I'll try creating new sound files with the delay included and see if that works. Thanks for your help.

  • Ok, I've removed the delay() from the code, but it's still messing up after a couple hours: code is still running but no sound is playing.

  • Does line 70 keep outputting values? What are they?

  • (it's hard for us to debug this without an Arduino, the files in question and a "couple of hours")

  • Does line 70 keep outputting values? What are they?

    Yes, it's printing the values that my Arduino is outputting, so it's printing "sit", "stand", and "move". When working correctly it prints those strings again and then plays the corresponding sounds. When it messes up it still prints the strings correctly but doesn't make any sound. On line 88 I added a check to see if the program still thinks that it's playing the sound files. That prints "sound2" both when working (playing the sounds) and when not working (not playing the sounds).

Sign In or Register to comment.