Go Down

Topic: Use of integers in libraries (Read 425 times) previous topic - next topic

rasmus91

Hey all.

After messing a bit around with arduino Libraries, i've run into some trouble, creating standard methods is easy enough, however when it concerns integers I run into some trouble.

this is what my code looks like:
Code: [Select]
/*prototypeGUI.h meant for C17's exercise prototype*/


#include "Arduino.h"
#include "prototypeGUI.h"
#include "serialLCDFunctions.h"

//prototypeGUI proto;

void prototypeGUI::startScreen(){
//Definition af startskærm
serialLCDFunctions::selectLineOne();
Serial.print("  Welcome to C17's");
delay(10);
serialLCDFunctions::selectLineTwo();
Serial.print(" Exercise prototype");
delay(10);
serialLCDFunctions::selectLineFour();
Serial.print("        >OK<");
delay(10);
}

void prototypeGUI::prototypeMenu(){
//Definition af menuen
serialLCDFunctions::selectLineOne();
Serial.print("     Choose exercise");
delay(10);
serialLCDFunctions::selectLineTwo();
Serial.print("         Calibration"); //Dunno if this is something that is needed
delay(10);
serialLCDFunctions::selectLineFour();
Serial.print("            Turn off");
delay(10);
}

int numberReps;
int numberBends;

void prototypeGUI::eWeightLift(){
//Definition af vægtløftøvelsen
serialLCDFunctions::selectLineOne();
Serial.print("Start exercise/pause");
delay(10);
serialLCDFunctions::selectLineTwo();
Serial.print("Nr. of bends:" + numberBends +);//Some integer containing a loop which keeps track of how many bends you have made. (NumberBends is just something i made up)
delay(10);
serialLCDFunctions::selectLineThree();
Serial.print("Nr. of reps.:" + numberReps); //Some integer containing a loop which keeps track of how many reps you have taken. (NumberReps is just something i made up)
delay(10);
serialLCDFunctions::selectLineFour();
Serial.print("                Back");
delay(10);
}


and the .h:

Code: [Select]
/*prototypeGUI.h meant for C17's exercise prototype*/

#ifndef prototypeGUI_h
#define prototypeGUI_h

#include "Arduino.h"
#include "serialLCDFunctions.h"

class prototypeGUI
{
public:

void startScreen();

void prototypeMenu();

void eWeightLift();

private:

};

#endif


But the integers used, namely:

Code: [Select]
numberReps;
and
Code: [Select]
numberBends;

makes the library not work, the specific error it gives is:
Quote
/home/rasmus/sketchbook/libraries/prototypeGUI/prototypeGUI.cpp: In member function 'void prototypeGUI::eWeightLift()':
/home/rasmus/sketchbook/libraries/prototypeGUI/prototypeGUI.cpp:45:45: error: expected primary-expression before ')' token


and I can't really see what im doing wrong here other than I am completely missing something about how I am supposed to put these integers into all of it. Please notice, that i should be able to change the integers values from my sketch.

thanks for looking this over :)

MarkT

The variables need to be in the class if used from class methods.

Also your indentation seems to be missing in the code...
[ I won't respond to messages, use the forum please ]

michael_x

Is it possible that line 45 is this one ?
Code: [Select]
Serial.print("Nr. of bends:" + numberBends +);//Some integer

45: error: expected primary-expression before ')' token
makes some sense, in that case.

Better use seperate Serial.print() expressions for the string and the number

rasmus91

Thanks, that really helped :D

Its incredible how blind i can sometimes be to the most obvious facts when it comes to programming.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy