Digital dice roller
Testing our dice roller
Here’s a demo of our electronic dice roller. The device has the piezo sensor connected to an “external interrupt” pin which can be used to wake the microcontroller from “deep sleep” (this means that after a period of inactivity, the device can shut down to conserve battery resources, but doesn’t need to be switched on or off via a switch between uses).
The basic premise is this:
When the interrupt first happens (the piezo is tapped) a timer is set running. If a second tap is detected before this timer hits 500 milliseconds, the device knows to roll two dice; if no second tap is detected, a single dice is “rolled”.
To roll the dice, a pseudo-random number is generated.
Within the Arduino library exists a pseudo-random number list; it’s basically a set list of numbers and each time you call the rand() function, the next number off the list is returned. Not so random, huh??
So whenever a dice roll is required, we sample the (floating) voltage from a disconnected pin and use this, along with the number of milliseconds that the device has been running, to determine where in this list of numbers we draw our next value from.
Since the analogue voltage on a disconnected pin is basically picking up atmospheric static, this means our seed number will always be some kind of random value; but even if perfect atmospheric conditions existed, and this value could be determined, by using the “milliseconds since start” it’s almost impossible to predict the starting point in the random number list – thus ensuring that the dice roll value returned is more or less truly random.
Now we’ve got it working, it’s time to miniaturise everything and try to squeeze it into an enclosure.
Leave a Reply