I would like to create my own library. Since I have used java programming so far, I do not know exactly how the header in C++ works. I tried to google it but it's a big topic.
Can someone advise me why I have a bug "error: expected unqualified-id before 'int'" in the LcdMenu.h???
And what's the problem with the String declaration???
I created it according to this example (https://www.arduino.cc/en/Hacking/LibraryTutorial)
If anyone knew about a tutorial that would be about creating a library, but without wide C++ knowledge
feel free to throw him into the comment.
My heder file
#ifndef LcdMenu
#define LcdMenu
#include <Arduino.h>
class LcdMenu
{
public:
LcdMenu(int _scrNr);
void addTextLine1(int _scrNr, String _line);
void addTextLine2(int _scrNr, String _line);
void addTextLine3(int _scrNr, String _line);
void addTextLine4(int _scrNr, String _line);
void setOnOff(int _scrNr, bool _onOff, String _ifTrue, String _ifFalse);
void setOnOff(int _scrNr, bool _onOff);
void setValue(int _scrNr, String _text, int _hodnotaI);
void setValue(int _scrNr, String _text, float _hodnotaF);
String getLine1(int _scrNr);
String getLine2(int _scrNr);
String getLine3(int _scrNr);
String getLine4(int _scrNr);
float getValue(int _scrNr);
float getLastValue(int _scrNr);
private:
int scrNr, arrayLenght;
float value, lastValue;
bool onOff;
String line1, line2, line3, line4, ifTrue, ifFalse;
};
#endif
My cpp file
#include "LcdMenu.h" //include deklaraciu tejto triedy
int scrNr, arrayLenght;
float value, lastValue;
bool onOff;
String line1, line2, line3, line4, ifTrue, ifFalse;
String myMenu[][];
//constructor
LcdMenu::LcdMenu(int _scrNr){
arrayLenght = _scrNr;
myMenu = new myMenu[arrayLenght][9]; //screen count // 9 = values
/*
* 0 - onOff
* 1 - line1
* 2 - line2
* 3 - line3
* 4 - line4
* 5 - ifTrue
* 6 - ifFalse
* 7 - value
* 8 - lastValue
*/
}
//destructor
LcdMenu::LcdMenu(int _scrNr){}
void LcdMenu::addTextLine1(int _scrNr, String _line){
myMenu[scrNr][1] = _line.substring(0,19);
}
void LcdMenu::addTextLine2(int _scrNr, String _line){
myMenu[scrNr][2] = _line.substring(0,19);
}
void LcdMenu::addTextLine3(int _scrNr, String _line){
myMenu[scrNr][3] = _line.substring(0,19);
}
void LcdMenu::addTextLine4(int _scrNr, String _line){
myMenu[scrNr][4] = _line.substring(0,19);
}
void LcdMenu::setOnOff(int _scrNr, bool _onOff, String _ifTrue, String _ifFalse){
myMenu[scrNr][0] = _onOff;
myMenu[scrNr][5] = _ifTrue;
myMenu[scrNr][6] = _ifFalse;
}
void LcdMenu::setOnOff(int _scrNr, bool _onOff){
myMenu[scrNr][0] = _onOff;
}
void LcdMenu::setValue(int _scrNr, String _line, int _valueI){
myMenu[scrNr][3] = _line;
myMenu[scrNr][8] = myMenu[scrNr][7];
myMenu[scrNr][7] = _valueI;
}
void LcdMenu::setValue(int _scrNr, String _line, float _valueF){
myMenu[scrNr][3] = _line;
myMenu[scrNr][8] = myMenu[scrNr][7];
myMenu[scrNr][7] = _valueF;
}
String LcdMenu::getLine1(int _scrNr){
return myMenu[scrNr][1];
}
String LcdMenu::getLine2(int _scrNr){
return myMenu[scrNr][2];
}
String LcdMenu::getLine3(int _scrNr){
return myMenu[scrNr][3];
}
String LcdMenu::getLine4(int _scrNr){
return myMenu[scrNr][4];
}
float LcdMenu::getValue(_scrNr){
return myMenu[scrNr][7].toFloat();
}
float LcdMenu::getLasValue(_scrNr){
return myMenu[scrNr][8].toFloat();
}
Thank you for your time and help...