Hello PaulS,
Again thank you for your reply. If i understand correctly the line:
// Initialise LiquidCrystal Object
LiquidCrystal LCD_Display(_pinRS, _pinE, _pin4, _pin5, _pin6, _pin7);
Creates a new object of LiquidCrystal? I don't fully understand how you define a new variable and how to define the one in the class, could you please explain a little bit about this?
I have been reading a bit about 'out of scope' but i don't understand why creating a new instance is immediately out of scope, isn't it created within the class or is my understanding of 'out of scope' not correct?
What i did now is the following for the header file:
#ifndef LCDSCREEN_H_
#define LCDSCREEN_H_
#include "LiquidCrystal.h"
class LCDScreen {
private:
int _pinRS;
int _pinE;
int _pin4;
int _pin5;
int _pin6;
int _pin7;
char chrBuffer[16];
void init();
public:
LCDScreen(int pinRS, int pinE, int pin4, int pin5, int pin6, int pin7) :
LCD_Display(pinRS, pinE, pin4, pin5, pin6, pin7)
{
_pinRS = pinRS;
_pinE = pinE;
_pin4 = pin4;
_pin5 = pin5;
_pin6 = pin6;
_pin7 = pin7;
LiquidCrystal LCD_Display(pinRS, pinE, pin4, pin5, pin6, pin7);
}
void DisplayMenu(int intMenuItem, double dblValue);
void Update(double dblValue);
virtual ~LCDScreen();
};
#endif /* LCDSCREEN_H_ */
And for the cpp file:
#include "LCDScreen.h"
#include "Arduino.h"
#include "LiquidCrystal.h"
LCDScreen::LCDScreen(int pinRS, int pinE, int pin4, int pin5, int pin6, int pin7) {
_pinRS = pinRS;
_pinE = pinE;
_pin4 = pin4;
_pin5 = pin6;
_pin6 = pin6;
_pin7 = pin7;
init();
}
LCDScreen::~LCDScreen() {
}
void LCDScreen::init() {
// Set Pin Modes
pinMode(_pinRS, OUTPUT);
pinMode(_pinE, OUTPUT);
pinMode(_pin4, OUTPUT);
pinMode(_pin5, OUTPUT);
pinMode(_pin6, OUTPUT);
pinMode(_pin7, OUTPUT);
// Set Output Pins To Low
digitalWrite(_pinRS, LOW);
digitalWrite(_pinE, LOW);
digitalWrite(_pin4, LOW);
digitalWrite(_pin5, LOW);
digitalWrite(_pin6, LOW);
digitalWrite(_pin7, LOW);
LCD_Display.begin(16,2);
LCD_Display.print("TC V1 - Bob");
}
I also tried declaring LiquidCrystal LCD_Display again but then i get some errors as well and i'm getting a bit confused right now so your help is very much appreciated.
EDIT: forgot to mention the errors that come up. When i don't declare the variable i get:
Multiple markers at this line
- Symbol 'LCD_Display' could not be resolved
- class 'LCDScreen' does not have any field named
with the LiquidCrystal LCD_Display; in the private area i get the following error:
'LCDScreen::LCDScreen(int, int, int, int, int, int)' previously defined here
redefinition of 'LCDScreen::LCDScreen(int, int, int, int, int, int)'
Does this mean i should define it but i can remove the constructor in the cpp file? Or am i really completely lost now?
Kind regards, Bob