NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Project Help and Ideas » 4 digit LED lib

 November 13, 2011 by claesz Hi guys! I had this 4 digit LED display laying around and decided to write a short lib for it. These displays are available on ebay and elsewhere for less than \$1 and are quite useful for displaying time and other numbers. The display requires 12 pins, but since it runs on interrupt, you can use the pins for other stuff outside the interrupts. Just keep the LOW pin for each digit off. My display is marked "5461AS" but all the similar looking displays I found on ebay had the same basic structure. The only thing that differed was whether the pin controlling each digit should be LOW or HIGH. This display requires this pin to be LOW and each "line controlling pin" to be HIGH. But depending on your display you may have to switch this around. Anyway, the library was hammered together in about an hour, so I am sure there is room for improvement. However, it seems to work. You can use fprintf to display data. Since these displays have no diagonal lines you really cannot display anything other than numbers (letters like "K", "R" and "H" would be impossible), so this lib is limited to numbers and decimal points. You can print f ex "12.00" or "12,00", "1,200", "120,0" or "1234". I included a LED brightness setting, so you can easily dim or increase the LED light. Might be useful for f ex an alarm clock where you want to dim the light during night hours. If someone has written a similar lib before, I apologize. If not, hopefully some of you may find it useful. This is the lib: ``````#include #include "../libnerdkits/delay.h" #include // You need to define the pins you have used for the LED display. 12 pins in total // LED pin 12, 9, 8 and 6 control the LOW of each digit. The rest controls each line in the // digit. Outside interrupts you can use the other pins for whatever you want, as long as // 12, 9, 8 and 6 are kept LOW. #define LEDPN1 (1< #include #include "../libnerdkits/delay.h" #include "../libnerdkits/io_328p.h" #include "./5461AS.h" int main() { LED5461_start(); FILE LED5461_stream = FDEV_SETUP_STREAM(LED5461_print, 0, _FDEV_SETUP_WRITE); LED5461_brightness = 500; while (1) { LED5461_home(); fprintf_P(&LED5461_stream, PSTR("12,34")); delay_ms(1000); LED5461_home(); fprintf_P(&LED5461_stream, PSTR("1,234")); delay_ms(1000); LED5461_home(); fprintf_P(&LED5461_stream, PSTR("1010")); delay_ms(1000); LED5461_home(); fprintf_P(&LED5461_stream, PSTR("9876")); delay_ms(1000); } return 0; } `````` Don't know why I decided the letter "H" would be impossible to do. It is probably one of the few that would work well :) I meant to say that "H" and "K" would be indistinguishable. At least unless you got really creative. As usual I end up having public discussions with myself about my own code. Sorry about that. However I also realized that number "9" in my lib is written without the traditional bottom line (it usually looks like a lower case "g"). If you are a sticker for tradition, just change 0b11100110 to 0b11110110 in the lib code. Well I enjoy it when I see other people talk to themselves, it re-asures me that I am not alone. Actually this is a very interesting project, which I can see use for, so thank you for your post. Ralph Thanks! Good to know it is not only me.