0

Currently setting up a function to declare the cases for a 4-part seven-segment display (a digital alarm clock basically) but keep getting errors when trying to confirm that it is properly set (Specifically from the core opening line) Have tried looking around, but nothing is specific enough to the arrays I need.

Just a note on the code. I have not properly set up a code block before, so I am unsure as to how to highlight syntaxes. If it is properly set up, just ignore this message Originally had it set as int SegmentWrite(int...[]) but would not produce results. Other tests I have tried is including a size [10][7] before the opening braces, to declare count and size, changing type from byte to int, char, and float (although only byte produced any sort of result, not being what I wanted)

void SegmentWrite (int SegmentDigits[]){
  byte SegmentDigits = zero[7] {1,1,1,1,1,1,0};//0
                  one[7] = {0,1,1,0,0,0,0};//1
                  two[7] = {1,1,0,1,1,0,1};//2
                  three[7] = {1,1,1,1,0,0,1};//3
                  four[7] = {0,1,1,0,0,1,1};//4
                  five[7] = {1,0,1,1,0,1,1};//5
                  six[7] = {1,0,1,1,1,1,1};//6
                  seven[7] = {1,1,1,0,0,0,0};//7
                  eight[7] = {1,1,1,1,1,1,1};//8
                  nine[7] = {1,1,1,1,0,1,1}; //9

This particular snippet of code isn't supposed to do anything - not on it's own, at least. When verifying, to confirm proper formatting, I only got the error report "declaration of 'byte SegmentDigits' shadows a parameter' with the first line highlighted. -Just a note, found another error, specifically with the opening line - "declaration of 'SegmentWrite' as array of void" or "'SegmentWrite' declared as function returning an array"

3
  • The formatting isn't the problem with the above; the basic issue is it isn't valid C in the first place. The error you received is actually a warning, and an important one, but the code above declares a local byte variable (single) called SegmentDigits , the same name as the formal parameter. That they're entirely of different types is just salt in the wound. The subsequent lines having no type whatsoever should be an obvious problem. Commented Oct 20, 2019 at 23:54
  • Depending on the rest of the code maybe you should encode the bits of the seven segments into a 8 bit byte and not into ten byte arrays. If you can write all GPIO pins with one word write this is definitely the way to go instead. Commented Oct 20, 2019 at 23:54
  • WhozCraig, not sure if the edits I made will give any information on my current errors - I am a student, and my prof used that specific variable byte for it - Not sure if that makes it any different or not. So I would want to set it up as C void SegmentWrite(void SegmentDigits[])[10][7]{ or remove the voids, replacing them with int? I apologize for my newbieness to coding, I hope this sort of defines my problem a bit more Commented Oct 21, 2019 at 0:02

1 Answer 1

1

You need to use a different name for the parameter array and the local array in the function.

Also, the function should take another parameter, the digit that you're trying to display.

You should then declare a 2-dimensional array, and you can use the digit as an index into it.

void SegmentWrite (int SegmentDigits[7], int digit){
    int allSegmentDigits[][7] = {
        {1,1,1,1,1,1,0},//0
        {0,1,1,0,0,0,0},//1
        {1,1,0,1,1,0,1},//2
        {1,1,1,1,0,0,1},//3
        {0,1,1,0,0,1,1},//4
        {1,0,1,1,0,1,1},//5
        {1,0,1,1,1,1,1},//6
        {1,1,1,0,0,0,0},//7
        {1,1,1,1,1,1,1},//8
        {1,1,1,1,0,1,1}} //9
    memcpy(SegmentDigits, allSegmentDigits[digit], sizeof allSegmentDigits[0]);
}
Sign up to request clarification or add additional context in comments.

3 Comments

Oops, rookie mistake!
Just figured the previous part out - asking around some friends as well, saying the Arduino (That's what I am working with) automatically gives priority in array order. What's the second line for, specifically the memcpy? -Coding in default C, didn't find anything in the Arduino reference
I assumed the purpose of the function is to fill in the SegmentDigits array with the appropriate values. memcpy() copies one of the rows of the 2D array into that array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.