I’ve had a few parts setting around a while for an upcoming electronics project, but it hasn’t gotten far off the ground because I was too lazy to spec out the control circuitry. I wanted it to be microcontroller based, but realizing that serial and parallel ports are ever-dwindling, I also wanted to make sure that I purchased/built a programmer that would still work in a few years’ time. Enter the Arduino, a perfect little development board based around the Atmel ATmega8; at only $30 for the board and chip, it’s a great deal. The chip comes pre-programmed with a bootloader that you can use over USB to upload your programs.
Programming the microcontroller is a snap. The Linux toolchain features a port of gcc and a small libc. There’s also watered down dialect of C and an IDE that noobs can use, but I just skipped to building with the arduino libraries and avr-gcc directly. Within 15 minutes of installing the necessary packages, I had my first program uploaded and blinking an LED. Pictured above is the second try, a simple RGB pixel consisting of 3 LEDs which fade among themselves (the effect is less than perfect without a good diffuser and smaller LEDs).
Here’s the code for the fade:
#include <WProgram.h> int rpin = 9; int gpin = 10; int bpin = 11; static int cols[3], i; void setup() { pinMode(rpin, OUTPUT); pinMode(gpin, OUTPUT); pinMode(bpin, OUTPUT); cols[0] = 255; cols[1] = 0; cols[2] = 0; } void next_color() { int before = i-1; if (before < 0) before = 2; if (cols[i] < 255) cols[i]++; else if (cols[before] > 0) cols[before]--; else i = (i+1) % 3; } void loop() { next_color(); analogWrite(rpin, cols[0]); analogWrite(gpin, cols[1]); analogWrite(bpin, cols[2]); delay(10); }