(right dice was the first one)
Tutorial for a DIY dice with Attiny85, Tilt sensor, Charlieplexing, Crystal resin.
it's easy way to build your own little electronic dice for good price.
French version on my blog
- Attiny 85 with socket
- Tilt sensor
- 39 ohms resistors
- Crystal resin
- gloss for crystal resine
- ice cube tray 3x3x3 cm
Step 1: Wiring the Dice
The rule usable to define the number of leds that you can drive with a number of pins :
(nbpin x nbpin) - nbpin
With 4 pins it's possible to drive 12 leds, with 3 pins only 6 leds. We need to drive 7 leds ==> we need to use 4 pins.
Use the Attiny socket to simplify the wiring.
Attiny Pin 1 - Resistor - Line 1 (blue)
Attiny Pin 2 - Resistor - Line 2 (green)
Attiny Pin 3 - Resistor - Line 3 (red)
Attiny Pin 4 - Resistor - Line 4 (black)
in a second time wire the button battery.
Attiny gnd - button battery (-)
Attiny Pin + - tilt sensor - button battery (+)
I use the tilt sensor as an interruptor.
Step 2: Programming the Dice
Compile and Upload the sketch
If it's your first time with Attiny 85, follow this link : http://highlowtech.org/?p=1695
Load the Attiny 85 sketch (i use a arduino as a ISP).
upgrade speed clock at 8 MHz.
Understand the sketch
2 libraries :
- Entropy : used for random and replace the wrong standard random function.
- EEPROM : used to write in Attiny and perform the randomseed number after each switch off.
2 two dimensions arrays :
- tabled  : used to map led and pins
- dede  : used to group led for representing the dice number.
- afficheled(int numled,int temps) : Display one led (numled) for a delimited time (temps)
- affichede(int n ,int temps) : Display the dice number (n) for a delimited time (temps)
- Lancedes() : dice generation. this function show several number before the final one.
Step 3: Build the Dice
You need to protect the button battery place against the resin, i use playdoh.
When you mix the resin with hardener, wait until the air bubbles disappear.
One complete week for drying the dice.