Hi all
I'm a coding beginner, so my question maybe isn't Arduino specific, but I'm not sure what I need to search for exactly.
This is my code which works fine, but it is only for one display:
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
const int tempPin = 0;
const int HHeinPin = 2;
const int OBfreigabePin = 3;
const int OBeinPin = 4;
const int MischerPin = 5;
const int BLswitchPin = 12;
const int minTemp = 55;
float temp;
int HHein = 0;
int OBfreigabe = 0;
int OBein = 0;
int Mischer = 0;
int Backlight = 1;
int BLswitch = 0;
int MischerBlink = 0;
hd44780_I2Cexp lcd;
void setup()
{
pinMode (2, INPUT);
pinMode (3, INPUT);
pinMode (4, INPUT);
pinMode (5, INPUT);
pinMode (12, INPUT);
//Serial.begin(9600);
lcd.begin(20,4);
lcd.backlight();
}
void loop()
{
temp = analogRead(tempPin);
temp = temp * 0.1;
Mischer = digitalRead(MischerPin);
HHein = digitalRead(HHeinPin);
OBfreigabe = digitalRead(OBfreigabePin);
OBein = digitalRead(OBeinPin);
BLswitch = digitalRead(BLswitchPin);
if (Mischer == 0){
MischerBlink = 0;
}
if (Backlight == 1 && BLswitch == 1){
Backlight = 0;
lcd.noBacklight();
} else if (Backlight == 0 && BLswitch == 1){
Backlight = 1;
lcd.backlight();
}
lcd.setCursor(0,0);
lcd.print("Boiler: ");
lcd.print(temp);
lcd.print(" C ");
lcd.setCursor(0,1);
lcd.print("Holzheizung: ");
lcd.print(HHein ? "heizt " : "aus ");
lcd.setCursor(0,2);
lcd.print("Oelbr.: ");
lcd.print(OBfreigabe ? "deaktiviert " : "freigegeben ");
lcd.setCursor(0,3);
lcd.print("Oelbrenner: ");
lcd.print(OBein ? "heizt " : "aus ");
if (Mischer == 0 && Backlight == 1){
lcd.backlight();
}
if (temp <= minTemp && Mischer == 0){
lcd.noBacklight();
delay(800);
lcd.backlight();
delay(800);
}
if ((temp <= minTemp && Mischer == 1) || Mischer == 1){
MischerBlink = 1;
delay(350);
lcd.backlight();
delay(800);
lcd.noBacklight();
delay(800);
lcd.backlight();
delay(800);
lcd.noBacklight();
lcd.clear();
lcd.setCursor(1,1);
lcd.print("Heizmischer offen");
lcd.setCursor(3,2);
lcd.print("Boiler zu kalt");
delay(800);
lcd.backlight();
delay(800);
lcd.noBacklight();
delay(800);
lcd.backlight();
delay(800);
lcd.noBacklight();
lcd.clear();
delay(400);
}
if (temp >minTemp && Mischer == 0){
delay(500);
}
}
Sorry for the backlight on/off mess...
It's displaying heating data and the goal is to show the same information on two displays, which are in seperate rooms. This on it's own isn't a problem, but I need to turn off the backlight of the displays individually with a hardware switch pushbutton.
I tried that:
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
const int tempPin = 0;
const int HHeinPin = 2;
const int OBfreigabePin = 3;
const int OBeinPin = 4;
const int MischerPin = 5;
const int BLswitch0Pin = 11;
const int BLswitch1Pin = 12;
const int minTemp = 55;
float temp;
int HHein = 0;
int OBfreigabe = 0;
int OBein = 0;
int Mischer = 0;
int Backlight0 = 1;
int Backlight1 = 1;
int BLswitch0 = 0;
int BLswitch1 = 0;
int MischerBlink = 0;
hd44780_I2Cexp lcd0;
hd44780_I2Cexp lcd1;
void setup()
{
pinMode (2, INPUT);
pinMode (3, INPUT);
pinMode (4, INPUT);
pinMode (5, INPUT);
pinMode (11, INPUT);
pinMode (12, INPUT);
//Serial.begin(9600);
lcd0.begin(20,4);
lcd1.begin(20,4);
lcd0.backlight();
lcd1.backlight();
}
void loop()
{
temp = analogRead(tempPin);
temp = temp * 0.1;
Mischer = digitalRead(MischerPin);
HHein = digitalRead(HHeinPin);
OBfreigabe = digitalRead(OBfreigabePin);
OBein = digitalRead(OBeinPin);
BLswitch0 = digitalRead(BLswitch0Pin);
BLswitch1 = digitalRead(BLswitch1Pin);
if (Mischer == 0){
MischerBlink = 0;
}
if (Backlight0 == 1 && BLswitch0 == 1){
Backlight0 = 0;
lcd0.noBacklight();
} else if (Backlight0 == 0 && BLswitch0 == 1){
Backlight0 = 1;
lcd0.backlight();
}
if (Backlight1 == 1 && BLswitch1 == 1){
Backlight1 = 0;
lcd1.noBacklight();
} else if (Backlight1 == 0 && BLswitch1 == 1){
Backlight1 = 1;
lcd1.backlight();
}
lcd0.setCursor(0,0);
lcd1.setCursor(0,0);
lcd0.print("Boiler: ");
lcd1.print("Boiler: ");
lcd0.print(temp);
lcd1.print(temp);
lcd0.print(" C ");
lcd1.print(" C ");
lcd0.setCursor(0,1);
lcd1.setCursor(0,1);
lcd0.print("Holzheizung: ");
lcd1.print("Holzheizung: ");
lcd0.print(HHein ? "heizt " : "aus ");
lcd1.print(HHein ? "heizt " : "aus ");
lcd0.setCursor(0,2);
lcd1.setCursor(0,2);
lcd0.print("Oelbr.: ");
lcd1.print("Oelbr.: ");
lcd0.print(OBfreigabe ? "deaktiviert " : "freigegeben ");
lcd1.print(OBfreigabe ? "deaktiviert " : "freigegeben ");
lcd0.setCursor(0,3);
lcd1.setCursor(0,3);
lcd0.print("Oelbrenner: ");
lcd1.print("Oelbrenner: ");
lcd0.print(OBein ? "heizt " : "aus ");
lcd1.print(OBein ? "heizt " : "aus ");
if (Mischer == 0 && Backlight0 == 1){
lcd0.backlight();
}
if (Mischer == 0 && Backlight1 == 1){
lcd1.backlight();
}
if (temp <= minTemp && Mischer == 0){
lcd0.noBacklight();
lcd1.noBacklight();
delay(800);
lcd0.backlight();
lcd1.backlight();
delay(800);
}
if ((temp <= minTemp && Mischer == 1) || Mischer == 1){
MischerBlink = 1;
delay(350);
lcd0.backlight();
lcd1.backlight();
delay(800);
lcd0.noBacklight();
lcd1.noBacklight();
delay(800);
lcd0.backlight();
lcd1.backlight();
delay(800);
lcd0.noBacklight();
lcd1.noBacklight();
lcd0.clear();
lcd1.clear();
lcd0.setCursor(1,1);
lcd1.setCursor(1,1);
lcd0.print("Heizmischer offen");
lcd1.print("Heizmischer offen");
lcd0.setCursor(3,2);
lcd1.setCursor(3,2);
lcd0.print("Boiler zu kalt");
lcd1.print("Boiler zu kalt");
delay(800);
lcd0.backlight();
lcd1.backlight();
delay(800);
lcd0.noBacklight();
lcd1.noBacklight();
delay(800);
lcd0.backlight();
lcd1.backlight();
delay(800);
lcd0.noBacklight();
lcd1.noBacklight();
lcd0.clear();
lcd1.clear();
delay(400);
}
if (temp >minTemp && Mischer == 0){
delay(500);
}
}
This works, but it looks terrible. It can't be a good idea to duplicate everything for another display.
--> I've to wait 5mins to complete the post... (it exceeds 9000 characters)