Cant get my own Library to work

So I wrote a Library for using 4 separate 7 segment displays. I know it's probably poorly done but still, I have to begin somewhere. But upon trying to upload it to Arduino Leonardo i get this error message:
Arduino: 1.8.16 (Windows 10), Board: "Arduino Leonardo"

In file included from C:\Users\mrozy\Desktop\test_lib\test_lib.ino:1:0:

C:\Users\mrozy\Documents\Arduino\libraries\7segLED/7segLED.h:1:9: error: macro names must be identifiers

#ifndef 7segLED_h

     ^~~~~~~~~

exit status 1

Error compiling for board Arduino Leonardo.

Here are the files:
7segLED.zip (860 Bytes)
test_lib.ino (202 Bytes)
What did I do wrong?

"Identifiers" can't start with a digit. Filenames can, but not C++ 'identifiers' (names for variables, functions, classes...).

Hi
Thanks, but if I delete the 7 from every word in both .h and .cpp files, i get another error:

Arduino: 1.8.16 (Windows 10), Board: "Arduino Leonardo"

test_lib:2:53: error: no matching function for call to 'segLED::segLED(<brace-enclosed initializer list>)'

 segLED segLED({2, 3, 6, 5, 4, 1, 0, 7, 8, 9, 10, 11});

                                                     ^

In file included from C:\Users\mrozy\Desktop\test_lib\test_lib.ino:1:0:

C:\Users\mrozy\Documents\Arduino\libraries\segLED/segLED.h:22:3: note: candidate: segLED::segLED(int*)

   segLED (int pins[ ]);

   ^~~~~~

C:\Users\mrozy\Documents\Arduino\libraries\segLED/segLED.h:22:3: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'int*'

C:\Users\mrozy\Documents\Arduino\libraries\segLED/segLED.h:5:7: note: candidate: constexpr segLED::segLED(const segLED&)

 class segLED {

       ^~~~~~

C:\Users\mrozy\Documents\Arduino\libraries\segLED/segLED.h:5:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const segLED&'

C:\Users\mrozy\Documents\Arduino\libraries\segLED/segLED.h:5:7: note: candidate: constexpr segLED::segLED(segLED&&)

C:\Users\mrozy\Documents\Arduino\libraries\segLED/segLED.h:5:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'segLED&&'

exit status 1

no matching function for call to 'segLED::segLED(<brace-enclosed initializer list>)'

Your constructor takes an array of pins. Unlike some languages, you can't make an array just by putting brackets around a list of values. Try it this way:

const int pins[] = {2, 3, 6, 5, 4, 1, 0, 7, 8, 9, 10, 11};
 segLED segLED(pins);

and inside your constructor, you reference that array from 1..12 which is not correct. It should be 0..11. pins[12] is out of bounds.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.