Thread: LED panel display

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    7

    LED panel display

    Hi im new to C programming and im having trouble with one of my projects..I dont know how to start it off.
    Basically this is what i gotta do:

    Write a C program that emulates a simple LED panel display. The program must implement the required features below:
    Accept one input integer from standard input.
    Print text to standard output which resemble a LED panel display of the input value (see examples below).
    Correctly process input values from zero to 9999.
    Print an error message to standard output when the input value is not supported by the program.

    The suggested size of each LED digit is 3x5, but, students may choose a larger size.

    The program must include source code comments to explain the design of the program.

    any help will be greatly appreciated

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    its best to do this incrementally. first, just implement a program that reads the input using scanf, and either printf's the value or an error message. don't worry about the LED display yet. once you have the input and verification handled, then you can start on the LED part of the display in place of just printf'ing. since you are printing to standard output, you will want to draw the digits row by row. so you would first loop over the rows (5?) and then loop over each digit and print the asterisks (or whatever) for that row and digit.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Pursuant to dmh2000's suggestion, here's how you can declare a set of arrays containing the numbers:

    Code:
    const char Numbers[4][5][4] = {
    	{" _ ",
    	 "| |",
    	 "| |",
    	 "| |",
    	 " - "},
    
    	{"_  ",
    	 " | ",
    	 " | ",
    	 " | ",
    	 " - "},
    
    	{" - ",
    	 "  |",
    	 " - ",
    	 "|  ",
    	 " - "},
    
    	{" - ",
    	 "  |",
    	 " - ",
    	 "  |",
    	 " - "}
    };
    Notice there are no newlines in the strings -- the idea is you can use, eg,

    Code:
    	for (i = 0; i < 5; i++) {
    		printf("%s %s %s\n", Numbers[1][i], Numbers[2][i], Numbers[3][i]);
    	}
    You will have to think about how to do that more dynamically, of course, to match your input.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    I had trouble visualizing fitting digitis into 3x5, but MK27's suggestion fixed that.
    I would have gone with outputting...
    Code:
    * * * *
    *     *
    *     *
    * * * *
    *     *
    *     *
    * * * *
    ... but we didn't get to see "see examples below" from the original problem.

  5. #5
    Registered User
    Join Date
    Dec 2011
    Posts
    7
    these are the examples im given
    For example, the input below:
    1290

    Must produce an output similar to:
    http://cnfolio.com/media/B142L_cw_led_example.jpg

    After successfully implementing the required features, students may optionally implement one or more of the features below:
    • Display output that resembles uppercase letters and/or lowercase letters.
    • Provide user option to choose inverted background display.

    As an example of the optional invert feature, the input below:
    i1290

    Should produce an output similar to:
    http://cnfolio.com/media/B142L_cw_le...ple_invert.jpg

  6. #6
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    I think by now we should be seeing some code. Things that should be working: How to enter an integer; error message when input was out-of-range; logic to split the integer apart at its digits; some logic for assembling the segments, or alternatively outputting entire digits.

  7. #7
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Definitely nicer then mine, lol. Like nonoob, for some reason I had trouble seeing how do a 3x5 scale without _, - and |, but obviously I thought wrong.

    The principle is still the same tho. If you have trouble, post your code here and someone will help.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #8
    Registered User
    Join Date
    Dec 2011
    Posts
    7
    basically im going to represent each number like this
    printf("000\n 0\n000\n0 \n000\n")
    thats the number 2
    i think i have the basic idea, but im still not sure as how to get it to read 4 digits on one line

  9. #9
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by aliali99 View Post
    basically im going to represent each number like this
    printf("000\n 0\n000\n0 \n000\n")
    thats the number 2
    i think i have the basic idea, but im still not sure as how to get it to read 4 digits on one line
    Did you even bother to read any of the posts in this thread yet? Go back and have a look at #3 again.

    post #3

    Read ALL of it. Consider this part:

    Quote Originally Posted by MK27
    Notice there are no newlines in the strings
    Think about WHY. Try the code. All it is missing is a main(). Here's the output:
    Code:
    _    -   - 
     |    |   |
     |   -   - 
     |  |     |
     -   -   -
    All apologies for my gimpy numbers, but there they are on one line. Pay attention, life is much easier that way.
    Last edited by MK27; 12-22-2011 at 11:11 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  10. #10
    Registered User
    Join Date
    Dec 2011
    Posts
    7
    like i said, im relatively new to this. i understood the post to an extent

  11. #11
    Registered User
    Join Date
    Dec 2011
    Posts
    7
    and i get this error when i compile it
    Line 5ERROR: parameter 'Numbers' is initialized
    compilation terminated due to -Wfatal-errors.

  12. #12
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    O_o
    You're new at this alright. That's okay. A 3 dimensional char matrix is a weird beast, but I'm sure that's what you're going to need.

    Code:
    #include <stdio.h>
    
    /* WRT [4][5][4]:
     * [4], 1st dimension = # of numbers
     * [5], 2nd dimension = # of lines in each number
     * [4], 3rd dimension = # of characters in each line INCLUDING NULL TERMINATOR!!
     */
    
    const char Numbers[4][5][4] = {
        {"ooo",
         "o o",
         "o o",
         "o o",
         "ooo"}, // <- pay attention to where these commas are
    
    // notice you can break the definition up onto lines
    // for simplicity, here's "1" without them
    
        {" o ", " o ", " o ", " o ", " o "},
     
        {"ooo",
         "  o",
         "ooo",
         "o  ",
         "ooo"},
     
        {"ooo",
         "  o",
         "ooo",
         "  o",
         "ooo"}
    };
    
    int main(void) {
    	int i;
    	for (i = 0; i < 5; i++) 
    		printf("%s %s %s\n", Numbers[1][i], Numbers[2][i], Numbers[3][i]);
    	
    	return 0;
    }
    So the more aesthetically pleasing version:

    Code:
    root~/C»./a.out
     o  ooo ooo
     o    o   o
     o  ooo ooo
     o  o     o
     o  ooo ooo
    The tricky part is going to be using that dynamically based on the input. I think you will need five for(i = 0; i < number of digits; i++) loops, one for each line.

    But I'm not going to write the whole thing for you -- you stand to get in trouble, remember. It is homework, you need to sweat and think, and next time: post some code!
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  13. #13
    Registered User
    Join Date
    Dec 2011
    Posts
    7
    wow thanks for that, makes a lot more sense now. i ll post some code up soon

  14. #14
    Registered User
    Join Date
    Dec 2011
    Posts
    7
    sorry for the lack of replies, ive been busy with other cwks/exams

    this is the code i have so far, but whenever i try run it, it says fatal run time error:
    insert
    Code:
    int main()
    {
        char input[70];
        
        for (int i = 0; i < 5; i++) 
            printf("%s %s %s %s\n", Numbers[input[7]][i], Numbers[input[1]][i], Numbers[input[2]][i], Numbers[input[9]][i]);
            scanf("%d %d %d %d\n", &Numbers); 
    
    
        return 0;
    }

    i feel to cry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. front audio panel
    By crvenkapa in forum Tech Board
    Replies: 1
    Last Post: 12-09-2007, 01:00 PM
  2. Windows CE 5.0 Software input panel
    By microstar in forum C++ Programming
    Replies: 1
    Last Post: 11-20-2007, 03:40 AM
  3. DirectX Control Panel Console
    By Tonto in forum Game Programming
    Replies: 1
    Last Post: 06-12-2007, 11:25 PM
  4. Add your self to the control panel
    By Queatrix in forum Windows Programming
    Replies: 1
    Last Post: 10-03-2006, 03:26 PM
  5. New Control Panel Applet
    By Franchie in forum C Programming
    Replies: 1
    Last Post: 05-12-2004, 12:33 PM