First time posting so apologies for the amateur question, but I want to get some ideas on the right direction before falling too far into the rabbit hole.
I am wanting to build a gag mood dial project for a lawn. It will be a circular dial with an arrow that randomly points to happy, sad, annoyed, afraid, etc.; you get the picture. My challenge is that I want the dial to move a random amount of times at random points throughout the day for a random amount of time (like spin for 20 seconds one time while spinning or only 5 for another). Oh yeah, a lot of randoms. It will hook up to a dawn/dusk timer so its not constantly running 24/7 and the arrow is on a stepper motor so the positioning also works. In short, is the following thought process feasible and how would I go about achieving it?
As power is supplied to the Arduino, it runs a setup function to create an array. This array will be of random length between two set values. This array is then populated with random numbers in ascending order. This will essentially create the random number of random start times throughout the day. The millis function is used to keep track in order to run a "for" statement when the elapsed time reaches one of the start times in the array which then initiates the dial for a random amount of time.
No, you are starting the project at the conclusion and working backwards to define the details. All with absolutely no way to test any of the intermediate steps.
You have something with a moving dial and a moving arrow all mounted on something that will be outside 24/7.
Get something built and then think about a way to control it and program code to do the control. And test each individual step with the built device.
* Determine the number of pulses (TP) for a full rotaiton of the arrow.
-- you must test that (N rotations * TP) always returns to the starting point.
-- provide N number-of-moods so that each is spaced by the same
fractional number of TP, (MS).
-- test that N * MS always centers on some mood position.
* Now you can generate any random offset NM = (1 to (number-of-moods - 1) * MS)
to choose your next mood position.
* Now you can generate a random number of full rotations before the motor
stops (TR = FR * ran( 1 thru N )).
* Now you can calculate the total number of pulses to the next position:
TR + NM = total number of pulses to next position.
I basically wanted to consolidate all the calculations it would be doing to the setup phase (if thats even possible). That way it wouldnt be constantly trying to calculate a new random time in the loop. So that when its in the loop phase the controller would literally be executing an established timetable.
Im probably making this far more complicated than it needs to be.
Thats what I originally envisioned and then all of a sudden it got messy with needing calculations within calculations. Im going to try and start from scratch through. This cant be that complicated. However, the random populated array does still interest me and I do want to see if its possible even if its purely from an academic curiosity perspective.
Why is that a problem? Calculating a random number takes almost no time. The Nano will have more than enough speed to do what you want.
If you need to output tens of thousands of these random numbers in a second, then pre-calculating and storing them might be a good idea. But your code will take literally all day to output what it has pre-calculated.
What the Nano does not have is very much memory, which is what would be needed to store a day's random numbers. So far better to calculate the random numbers when they are needed and not store them.
Established, maybe, but random. No point compiling a train timetable if the trains arrive at random times!
I want to thank you for your input. Turns out I was a massive goober and gcjr's response ended up working perfectly. I made this far more difficult than necessary and let myself fall down the rabbit hole completely.