Home Forums Sparkfun MP3 Shield Library Support Forum Not all the songs are playing with the Random Play Code

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #3543
    Anonymous
    Inactive

    Hi –

     

    I’m using MPFlaga’s Random Play code and for the most part it’s working great.  Thank you for posting.

    But it’s not playing all the tracks.  It will play one track multiple times in a row and then maybe go to another track and play that one twice.

    There are 10 tracks on the SD card.  Do I need to change the random number in this line of code?

    rantrack = random(0);// find random number

    Thank you!

     

    #3544

    I assume you are referring to https://gist.github.com/mpflaga/5800889

    as per https://www.arduino.cc/en/Reference/Random

    random(max)
    random(min, max)

    where the GIST example is set to 5, so I believe it outputs a range from 0-4 randomly.

    In your comments I am not hearing that the order is repeatable. If that were the case you could try a different random seed and see if that changes the behavior “randomSeed(analogRead(0));” However I do believe it is a random seed, as the seed is after the MP3 and SdCard init, where the SdCard has asynchronous timing responses, sufficiently random.

    I not your above line of code “rantrack = random(0);” This should only output a range of zero to zero or just zero, not good.

    I will say with small ranges Random can quiet often be very repeatable, sounds like you really want pseudo random, in that it does not play repeats.  So I have updated the above GIST as not to replay repeats. It does compile, but I have not tested it. However, it is straight forward and expect it to.

    #3545
    Anonymous
    Inactive

    Thank you!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.