danieljon.es

index posts opinions likes dislikes interesting cgit

Posts

My posts about programming and things.
Date format is day/month/year because I'm sane.

A simple binary counter and LED matrix

20/12/2018



Using this same technique I emulated an 8x8 LED matrix and created a bouncing ball demo. The code can be found in my git repo.



#include <stdio.h>
#include <unistd.h>

// website generator breaks with unicode, so fill in the unicode characters yourself
#define CIRCLE "CIRCLE"
#define BLACKCIRCLE "BLACKCIRCLE"

void
printleds(unsigned char value)
{
	printf("\0337");
	printf("%s", "\033[1;0F");
	printf("%s", "\033[0J");
	printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
			(value & 1 << 7) ? BLACKCIRCLE : CIRCLE,
			(value & 1 << 6) ? BLACKCIRCLE : CIRCLE,
			(value & 1 << 5) ? BLACKCIRCLE : CIRCLE,
			(value & 1 << 4) ? BLACKCIRCLE : CIRCLE,
			(value & 1 << 3) ? BLACKCIRCLE : CIRCLE,
			(value & 1 << 2) ? BLACKCIRCLE : CIRCLE,
			(value & 1 << 1) ? BLACKCIRCLE : CIRCLE,
			(value & 1 << 0) ? BLACKCIRCLE : CIRCLE
	      );
	printf("\0338");
}

int
main(void)
{
	unsigned char value = 0;
	while (1)
	{
		printleds(value);
		value++;
		if (value >= 255)
			value = 0;
		sleep(1);
	}
	return 0;
}


page generated 16-03-2019 13:35:18 using sitegenerator