This project was for creating a dice that using an accelerometer would randomly generate numbers. The electronics were based on an Adafruit Trinket microcontroller, Adafruit 8x8 LED matrix, and an Adafruit MMA8451 Accelerometer breakout board. The programing was done with the Arduino IDE as the Trinket was comparable with that system.
To make the 1k limit, I needed to disable some interrupt code in the core Arduino code. This process was documented in the project log and software build instructions.
This dice works by using the face orientation of the accelerometer to detect rotations and trigger a new number generation event. I created a loop and checked for orientation changes for a set number of iterations. If the change threshold was met, the dice number was updated. To get a quasi-random number I created a temporary value and for each loop for the orientation check I added the loop number and the orientation enum value. This will be quasi-random because the dice roll will determine when the threshold is met and it would be hard to discern when this would happen. Its not perfect but uses very little memory and gives a pretty reasonable series of numbers.
The dice is powered with two CR2025 batteries and has an on/off button. There is still a lot of the free space on device so a lot more features could be added. There is space on the matrix for at least two digit numbers and another button could be added to change the max number being generated.
Here is a video of the dice in operation:https://drive.google.com/open?id=0B-pKTjS6J01NaHBHc2tzUFY1dmc
Code is posted at https://github.com/fsleeman/accel-dice.