Tuesday, January 5, 2016

An electronic dice roller in assembly language

I've recently been going through a tutorial series on programming for the AVR in assembly language. I found this tutorial on Instructables, and have found it really fascinating.

The Arduino IDE certainly makes programming the Arduino easy, but I really enjoy the nuts and bolts of it all.  I suppose that is why I like to play with electronics and computers in the first place. So I've never really been one who enjoys black boxes, but rather, I always like to crack open the box and understand what makes it tick.

Also, I've been using a breadboard-based microcontroller lately, rather than hooking up a circuit to a pre-fab Arduino board.  There are instructions for how to create a breadboard arduino on the arduino.cc site at https://www.arduino.cc/en/Main/Standalone.

The latest gadget I built was an electronic dice roller, based on the 4th tutorial in the series. The microcontroller is attached to two banks of LEDs in the shape of a pair of dice. The anode of each dot in one die is wired to a pin on the ATmega328 and also to the anode of the corresponding dot on the other die.  So the LEDs of the middle dots of both dice are wired together and then wired to the microcontroller with a single wire.  The cathodes of all of the LEDs on one die are also tied together, and then wired back to a single pin on the MCU through a 330 Ohm resistor.  The cathodes of each die are tied to a different pin.  By alternating which pin is active, the program can alternate which die is lit.  When die 1 is lit, it activates the appropriate dots for that die.  When die 2 is lit, it activates a different set of dots.  As it does this fast enough, the eye does not notice and thus 14 LEDs are controlled by 9 pins.

If you're interested in seeing it in action, I've included a video.