This website was originally written in Ruby and hosted on the Raspberry Pi. It's now archived at GitHub for posterity!

C, See

Pushing the boat out to C, another lanuage which I've somehow avoided becoming familiar with, I decided to re-write my Ruby LED Binary Clock entirely in C. The code isn't brilliant, with a glut of consecutive "if" statements to determine which LEDs should be turned on. But it works!

Here's a snippet outlining a new idea I had whilst working in C, phasing the "off" phase of the LEDs to give a cool, pulsing up/down effect.

slept = 0;

for(x = 13;x >= 0;x--)
	int status;
	int led = leds[ x ];
	status = digitalRead( led );
	if( status == 1 )
		slept += 20000;
		digitalWrite (led, LOW);
		usleep( 20000 );

usleep( 300000 - slept );

There are 14 LEDs being turned on with a 50ms delay between each one for a maximum time of 700ms (if all LEDs were to be lit) to turn them on. Thus I had 300ms left to turn them all off, so I used a delay of 20ms.

« Back to index Posted on 2012-06-20 by