Travel to outer space sounds very exciting but now we are here in our space ship and we have about 10 square meters for 5 people. It will take another week until we reach the first space station. I took my mp3 player with me and after so many days of travel I have heard every song at least a dozen times.
James was much more clever: He bought an electronic dice from shop.tuxgraphics.org because normal dice don’t work in the absence of gravity….
Let’s play ;-).
The electronic dice
A dice is essentially just a special display for numbers from 1 to 6.
Why is a real dice a random number generator? If your hand would have perfect precision mechanics and you could control speed and position exactly then a real dice would probably be deterministic. In other words the one tossing the dice is the one introducing the randomness.
If you look at the code for our electronic dice then you will see that it is just a counter. It counts up while you press a button. Why is this a prefect dice? It’s a dice because microcontrollers do operations in μs and humans are unable to control pushbuttons and time with the precision of μ-seconds. Even if you hit the pushbutton just for a moment the microcontroller’s counter will loop around 56 times, or 80 times, or 102 times,…. It’s impossible to control it precisely. It’s random.
The E-dice as a nice AVR project
The E-dice is a simple but useful AVR starter project.
The only polar components in this circuit are the atmega8 and the LEDs. The atmega8 has mark on the side where pin 1 is. The LEDs are always oriented such then minus pin is connected to the wire that leads finally to one of the atmega8 pins.
Which pin on the LED is minus and which is plus? By convention the longer wire is always the plus wire and the shorter wire the minus wire as shown in the picture on the right.
Let’s take a look at the code. This is the main part of the code.
The complete source code is available for download at the end of this article:
unsigned char i=0; initLEDports(); DDRB &= ~(1<<PINB0); // input line PORTB|= (1<<PINB0); // internal pullup resistor on
For more detail: An electronic dice using ATmega8
This free embedded project also found using:
- atmega8 powered dice