boxing timer sketch, not declared error

Hello everybody and thank you for reading.

I am a complete newby with Arduino but I like to learn it.

My problem is that I need a boxing timer and after some searching i found a complete sketch.
Lucky me, only I get an error and i don't know were to search for the solution.

anybody willing to help me out?

The sketch is in the attachement and i got the following errors:

Working with an arduino Uno board.

Thanks for your time.

Arduino: 1.8.5 (Windows 10), Board:"Arduino/Genuino Uno"

C:\Users\Alan\Documents\Arduino\BoxingTimer\BoxingTimer.ino:70:61: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

WorkoutInterval restInterval = WorkoutInterval("break", 60);

^

C:\Users\Alan\Documents\Arduino\BoxingTimer\BoxingTimer.ino:71:61: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

WorkoutInterval round1 = WorkoutInterval("Round1", 240);

^

C:\Users\Alan\Documents\Arduino\BoxingTimer\BoxingTimer.ino:72:61: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

WorkoutInterval round2 = WorkoutInterval("Round2", 240);

^

C:\Users\Alan\Documents\Arduino\BoxingTimer\BoxingTimer.ino:73:61: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

WorkoutInterval round3 = WorkoutInterval("Round3", 240);

^

C:\Users\Alan\Documents\Arduino\BoxingTimer\BoxingTimer.ino:74:61: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

WorkoutInterval round4 = WorkoutInterval("Round4", 240);

^

C:\Users\Alan\Documents\Arduino\BoxingTimer\BoxingTimer.ino:75:61: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

WorkoutInterval round5 = WorkoutInterval("Round5", 240);

^

C:\Users\Alan\Documents\Arduino\BoxingTimer\BoxingTimer.ino:76:61: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

WorkoutInterval round6 = WorkoutInterval("Round6", 240);

^

C:\Users\Alan\Documents\Arduino\BoxingTimer\BoxingTimer.ino:77:60: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

WorkoutInterval int60 = WorkoutInterval("Int60", 60);

^

C:\Users\Alan\Documents\Arduino\BoxingTimer\BoxingTimer.ino:78:60: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

WorkoutInterval int45 = WorkoutInterval("Int45", 45);

^

C:\Users\Alan\Documents\Arduino\BoxingTimer\BoxingTimer.ino:79:60: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

WorkoutInterval int30 = WorkoutInterval("Int30", 30);

^

C:\Users\Alan\Documents\Arduino\BoxingTimer\BoxingTimer.ino:80:60: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

WorkoutInterval int15 = WorkoutInterval("Int15", 15);

^

C:\Users\Alan\Documents\Arduino\BoxingTimer\BoxingTimer.ino:99:42: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

Workout("Boxing", 2, 1, boxingIntervals),

^

C:\Users\Alan\Documents\Arduino\BoxingTimer\BoxingTimer.ino:100:46: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

Workout("Workout3", 6, 1, workout3Intervals),

^

C:\Users\Alan\Documents\Arduino\BoxingTimer\BoxingTimer.ino:101:46: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

Workout("Workout4", 8, 1, workout4Intervals),

^

C:\Users\Alan\Documents\Arduino\BoxingTimer\BoxingTimer.ino:102:44: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

Workout("4 +2", 24, 0, fourPlus2Intervals),

^

C:\Users\Alan\Documents\Arduino\BoxingTimer\BoxingTimer.ino:103:52: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

Workout("4 +2 +1", 26, 0, fourPlus2Plus1Intervals),

^

C:\Users\Alan\Documents\Arduino\BoxingTimer\BoxingTimer.ino:104:52: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

Workout("4 +2 +2", 28, 0, fourPlus2Plus2Intervals)

^

BoxingTimer:113: error: 'drawMenu' was not declared in this scope

ScrollableMenu scrollableMenu(2, MENUS_COUNT, drawMenu);

^

exit status 1
'drawMenu' was not declared in this scope

Dit rapport zou meer informatie bevatten met
"Uitgebreide uitvoer weergeven tijden compilatie"
optie aan in Bestand -> Voorkeuren.

BoxingTimer-master.zip (71.6 KB)

That means that the argument type isn't declared const, so you are being warned that
the compiler cannot guarantee your constant strings won't be side-effected by the function call.

And drawMenu is undefined.

Here's the link to the library you forgot to include I think:

As you can see the WorkoutInterval class constructor doesn't declare name as "const char *",
and ScrollableMenu.h forgets to prototype the top level functions from ScrollableMenu.cpp

I suspect this codebase is stale and abandoned (5 years old).

The error is caused by a failure of the Arduino IDE's automatic function prototype generator. C++ requires that functions be declared before they are referenced in the code. For this reason, you would normally add a prototype for each function to act as a forward declaration. In order to make things easier, the Arduino IDE automatically generates function prototypes unless you have already added them manually. Although it normally does a very good job of this, under certain circumstances, it doesn't place the prototypes in the correct place. That is what happened here. The prototype generation system was completely reworked a few years ago and overall this resulted in significant improvements but this is one case where the old system worked better than the new one:

Likely this code was written some time ago, when it would have compiled fine as-is.

So the solution is to simply add your own function prototype for the drawMenu function by adding the following line somewhere above line 113:

void drawMenu(int menuItem, int row, char isActive);

The prototype generator doesn't add prototypes into .h files for .ccp functions in any library surely?

It only handles local files in the sketch's directory.

The whole point of a library is to encapsulate.

Most "deprecated" errors can be fixed with a cast. For example:

   Workout("Workout3", 6, 1, workout3Intervals)                  // One of your errors

   Workout( (char *) "Workout3", 6, 1, workout3Intervals)        // Should fix it

Adding the (char *) expression changes the attribute list from const char * for the function's parameter to char *, which is what many functions expect. That is, functions usually expect a variable name, not a constant (double-quoted) expression.

MarkT:
The prototype generator doesn't add prototypes into .h files for .ccp functions in any library surely?

That's correct. But this isn't a library. It's a sketch. All the relevant code is in BoxingTimer.ino.

MarkT:
It only handles local files in the sketch's directory.

More than that, prototype generation is only done for .ino files. It is not done for files with any other extension (e.g. .h, .cpp, .c, .S) in the sketch.

Adding the (char *) expression changes the attribute list from const char * for the function's parameter to char *, which is what many functions expect. That is, functions usually expect a variable name, not a constant (double-quoted) expression.

It is better to fix the function declaration to accept/expect const char , which tells the caller that the function promises not to fck with the contents of the string passed in.

Wauw what a lot of help on this forum.
Thanks guys.

My list with error is a lot shortened but I still have this same error ( see under)

I tried the advice from pert to add this line but then still errors:

void drawMenu(int menuItem, int row, char isActive)

BoxingTimer:112: error: 'drawMenu' was not declared in this scope

ScrollableMenu scrollableMenu(2, MENUS_COUNT, drawMenu);

Bibliotheek LiquidCrystal op versie 1.0.7 in map: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal wordt gebruikt
exit status 1
'drawMenu' was not declared in this scope

So, you changed your code, but failed to post the changed code.

My crystal ball has some recommendations, but I'm too polite to pass them along.

PaulS:
My crystal ball has some recommendations, but I'm too polite to pass them along.

Wow! They must be really bad!

PaulS:
So, you changed your code, but failed to post the changed code.

Hi PaulS, I thought the error message would be enough but next time I will think about it.

Anyway, reading all the friendly advices I decided to try an old arduino programm version.
And that did the trick. It is now compiling and uploading.
Now I have to wait that my display arrives and then I hope it works.

Thanks all for your time and energy, really appeciated.
Could not have done it without your advices.

regards Alan