Hi,
I have done init of LCD into setup of my main program.
a) Now I would like to delegate lcd.print to my util class Traces.cpp
I have done this by pointer but I would like to do it by reference
b) Furthermore, I have a problem cause the line below
Tracer.LCDPRINT("info");
display fugitive info before disappearing.
Thank you
Main.pde sketch
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
//
// SETUP
//
void setup() {
// SERIAL
Serial.begin(9600);
// LCD
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.clear();
delay(2000);
}
void loop() {
Tracer.PRINT("info ");
Tracer.LCDPRINT("info");
delay(1000); //waiting a second
}
Then the util Trace class
/*
traces.h - low level traces functions
*/
#ifndef _Traces_h
#define _Traces_h
#include "WProgram.h"
#include <inttypes.h>
#include <LiquidCrystal.h>
#include "Time.h"
class Traces
{
public:
Traces();
void PRINT(String pstr);
void BEGINPRINT(String pstr);
void ENDPRINT(String pstr);
// LCD
void setLCD(LiquidCrystal & plcd);
void LCDPRINT(String pstr);
private:
//
String sepDate ;
String sepHour ;
String sepMilli;
String sepTxt ;
//
String DATE();
LiquidCrystal *_lcd;
};
extern Traces Tracer; // make an instance for the user
#endif /* _Traces_h */
___________________________
/*
Traces.cpp for traces output.
*/
#include "WProgram.h"
#include "Traces.h"
#include "Time.h"
#include <Wire.h>
#include <Utils.h>
#include <DS1307.h> // written by mattt on the Arduino forum and modified by D. Sjunnesson
#include <LiquidCrystal.h>
Traces::Traces()
{
sepDate = "_" ;
sepHour = ":" ;
sepMilli= "." ;
sepTxt = ": ";
//
}
void Traces::PRINT(String pstr) {
Serial.println(DATE()+pstr);
}
void Traces::BEGINPRINT(String pstr) {
Serial.print(DATE()+pstr);
}
void Traces::ENDPRINT(String pstr) {
Serial.println(pstr);
}
//LCD PRINT
void Traces::LCDPRINT(String pstr) {
_lcd->setCursor(0, 0);
_lcd->print(DATE()+pstr);
}
void Traces::setLCD(LiquidCrystal & plcd){
_lcd = &plcd;
}
String Traces::DATE(){
String str ;
str+=convert::ToTwoDigits(RTC.get(DS1307_HR, true))+sepHour+convert::ToTwoDigits(RTC.get(DS1307_MIN, false))+sepHour+convert::ToTwoDigits(RTC.get(DS1307_SEC , false))+sepTxt;
return str;
}
Traces Tracer = Traces() ;