I am trying to write code for my Arduino Uno with Adafruit MP3 Music Maker Shield that plays a randomly selected song from an array whenever it is turned on, but every time I reset the board the
I can't figure out why no song is playing at all, I've used every resource I could find and still it will not work. Any and all help would be appreciated, more code and other information can be given upon request, thanks!
Your array of songs has 3 elements in it.
You are calling random(4), which returns a number from 0 to 3,
BUT:
If it returns 3 and you access array index3, you create a "buffer overflow" and access memory locations, where no valid data is stored!
In an array with 3 elements, the valid array index is 0,1, or 2 only!
If you want to have a random index number for accessing an array with 3 elements, better use random(3) instead!
BTW:What are your provisions to get a "true random number" from the "pseudo random number generator" function in Arduino?
When you take no provisions, you get the same sequence of numbers after each resetii.,e. the first access to random(4) or random(3) will always return the same number after each reset of the Arduino (power-on reset or pressing the reset button or auto-reset when opening the serial monitor!