x will most likely be 0 or 65535 when you apply power. Getting a truly random number is actually quite hard. Perhaps a long wire or PCB trace acting as an antenna feeding an analog input and sample it on power on.
/Henrik.
x will most likely be 0 or 65535 when you apply power. Getting a truly random number is actually quite hard. Perhaps a long wire or PCB trace acting as an antenna feeding an analog input and sample it on power on.
/Henrik.
One way to get a “sort of random number” is to start a timer, and then let the watchdog timer do a reset which will not ruin the timer values.
Then you can read them and you get different values each time in some limited range that you could multiply or divide.
The next time the program starts after the reset, the timer values will be non zero before you started the timer. Then service the watchdog timer from then on.
I left an example here at some stage that allowed a pic to determine from a list of specific values, what speed crystal is running the pic.
Another way might be to let the POT command do what it does, and time the discharge of a capacitor through a resistor.
You should be able to fiddle with resistor and capacitor values to make the POT command return inconsistent readings.
Can you add a pot?
I'd connect it to an analog input, read the value, establish a pause or loop on that value then start main loop.
Robert
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
Bookmarks