I tried making a custom menu library. The purpose would be that I could say 'menu1.all(string 1, string 2, string3, string4) and that the class would take care of the position of these 4 strings on the lcd. 1 on the top left, 2 on the top right etc.
When I define LiquidCrystal lcd(pinconnections) then I can't define it with the same pinconnections in my library.
I'd like to be able to use lcd.print("Hello"); in the main, but also the same lcd.print(..) in my own library.
I'm guessing I'll have to make the library know that the main program is already using an lcd, so that the library can use the same?
The default lcd program, editted to use my "menu" library:
#include <Wire.h>
// include the library code:
#include <LiquidCrystal.h>
#include <Menu.h>
Menu menu1;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd1(12, 11, 4, 5, 6, 7);
void setup() {
// set up the LCD's number of columns and rows:
lcd1.begin(16, 2);
// Print a message to the LCD.
menu1.all("a","b","c","d");
}
void loop() {}
The part of the library that should communicate with the lcd:
#include "Menu.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd1(22, 23, 24, 25, 26, 27);
void Menu::printMenu(){
lcd1.clear();
lcd1.setCursor(0, 0);
Serial.println(_lB.length());
String s;
if (_lB.length()>0) lcd1.print(_lB);
if (_rB.length() > 0) {
int pos = 16 - _rB.length() - 1;
lcd1.setCursor(pos, 0);
lcd1.print(" " + _rB);
}
if (_lO.length()>0) lcd1.print(_lO);
if (_rO.length() > 0) {
int pos = 16 - _rO.length()-1;
lcd1.setCursor(pos, 1);
lcd1.print(" " + _rO);
}
}
How can I pass-trough the 6 integers that define the lcd to my own class?
for instance in the main:
LiquidCrystal lcd1(pin1, pin2, pin4, pin5, pin6, pin7);
And in my library: lcd1(&pin1, &pin2,...)?