lolshield hacking
My friend Jimmie Rodgers, maker extraordinaire has come up with a great new shield for the Arduino which he is calling the LoLshield for “lots of leds”. It’s a charliplexed array of 126 LEDs in a 9×14 grid that pops right onto an arduino. Neat!
A problem with charliplexing is brightness. Since you have to turn each led on and off only one at a time, you must cycle them very quickly and rely on persistance of vision to make it look like many are on at once. The faster you can cycle, the brighter they will seem.
Arduino libraries can be very convenient, but some are slow. Using the original routine which called PinMode() and DigitalWrite() twice for each LED, only limited brightness could be achieved. I worked out a way to use direct port manipulation instead, a process which allows you to directly set the output mode and state of the pins of the ATMega very quickly – and set multiple pins at once to boot! Check out the Arduino Port Manipulation page for more.
Here’s how it works. At the heart, we have a 2D lookup array which contains 4 values for each of the 126 LEDs on the board. The values are what needs to be shoved into the corresponding DDR and PORT registers to turn each LED on. (I used a quick processing sketch to generate this) As an example, let’s walk through the 4 values stored for LED 0, the upper-left LED. It uses pin 13 as its positive pin, and pin 5 as its ground. The values stored are: {32, 34, 32, 0}
void turnon(int led) {int pospin = ledMap[led][0];int negpin = ledMap[led][1];pinMode (pospin, OUTPUT);pinMode (negpin, OUTPUT);digitalWrite (pospin, HIGH);digitalWrite (negpin, LOW);}
void turnonbin(int led){DDRB = ledMapBin[led][0];DDRD = ledMapBin[led][1];PORTB = ledMapBin[led][2];PORTD = ledMapBin[led][3];}
In: projects · Tagged with: DINO
