LED Segment Display on a Raspberry Pi

During my leisure time I made a LED segment display work using a Raspberry Pi. I have used a 74HC595 shift register and a LED segment display. This would be the circuit diagram.

View post on imgur.com


Actually all of this was done from the scratch. The SegCodes were found from Wikipedia http://en.wikipedia.org/wiki/Seven-segment_display

This is the program 🙂
[code language=”c”]
#include <wiringPi.h>
#include <stdio.h>

/*
https://github.com/OsandaMalith/
*/

#define SDI 0
#define RCLK 1
#define SRCLK 2

unsigned char SegCode[17] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x80};

void init(void){
pinMode(SDI, OUTPUT);
pinMode(RCLK, OUTPUT);
pinMode(SRCLK, OUTPUT);

digitalWrite(SDI, 0);
digitalWrite(RCLK, 0);
digitalWrite(SRCLK, 0);
}

void shift(unsigned char dat){
int i;

for(i=0;i<8;i++){
digitalWrite(SDI, 0x80 & (dat << i));
digitalWrite(SRCLK, 1);
delay(1);
digitalWrite(SRCLK, 0);
} digitalWrite(RCLK, 1);
delay(1);
digitalWrite(RCLK, 0);
}

int main(void){
int i;

if(!wiringPiSetup()) printf("Error Occured");
init();
printf("http://osandamalith.wordpress.com");
while(1) for(i=0;i<17;i++){
shift(SegCode[i]);
delay(500);
}

return 0;
}
[/code]

https://github.com/OsandaMalith/RaspberryPi/blob/master/led.c

Feels amazing when you write programs and control hardware 🙂 You can also use Python with the GPIO library to the above or any language as long as it supports GPIO capabilities. However being familiar with C programming I love to do most of the things in C.

Leave a Reply