mercredi 26 décembre 2018

New to arduino. "Random" values are repeating upon reset

I am coding a roulette game in arduino's C based environment that flashes LEDs to represent the ball circling and stopping. My problem is that the ball stops at the same location every time. I am using randomSeed(analogRead(0)) combined with random(min,max) to generate a random number. This random number represents where my ball "enters". However when I reset my arduino, I get the same exact results. Does anyone know where my problem may lie?

Some important notes

-I am calling random in the global scope because I want a single random starting point for my roulette game (where the "ball" enters). Would having randomSeed in the setup and random in the global scope cause a problem when these two work together? I am new to how "setup" interacts with the rest of the code in arduino.

-The random number I am generating is in a very small range (0-4). However I have reset my arduino many times and gotten 2 as the first number about 30 consecutive times.

I've also tried calling randomSeed in the global scope instead of setup but I get hit with the following error when I do so. " exit status 1 expected constructor, destructor, or type conversion before '(' token "

If there is any more details I can provide or if anyone knows of a post on a similar issue please let me know.




Aucun commentaire:

Enregistrer un commentaire