Pages: [1]   Go Down
Author Topic: Use of integers in libraries  (Read 361 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/*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:
/*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:
numberReps;
and
Code:
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 smiley
Logged

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11730
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Also your indentation seems to be missing in the code...
Logged

[ I won't respond to messages, use the forum please ]

Germany
Online Online
Faraday Member
**
Karma: 56
Posts: 2983
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is it possible that line 45 is this one ?
Code:
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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, that really helped smiley-grin

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

Pages: [1]   Go Up
Jump to: