The function does not work on a differential thermostat.

Hello.
I'm new to programming and I can't understand why the DiferentH function can't increase and decrease diferentHi
Thanks in advance.

[#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte custom0[] = {
 B00000,
 B00100,
 B00100,
 B00100,
 B11111,
 B01110,
 B00100,
 B00000
};

byte custom1[] = {
 B00000,
 B00100,
 B00100,
 B00100,
 B11111,
 B01110,
 B00100,
 B00000
};

byte custom2[] = {
 B00000,
 B00000,
 B00000,
 B00000,
 B00000,
 B00000,
 B00000,
 B11111
};
byte custom3[] = {
 B00000,
 B00000,
 B00000,
 B00000,
 B00000,
 B00000,
 B11111,
 B11111
};
byte custom4[] = {
 B00000,
 B00000,
 B00000,
 B00000,
 B00000,
 B11111,
 B11111,
 B11111
};
byte custom5[] = {
 B00000,
 B00000,
 B00000,
 B00000,
 B11111,
 B11111,
 B11111,
 B11111
};
byte custom6[] = {
 B00000,
 B00000,
 B00000,
 B11111,
 B11111,
 B11111,
 B11111,
 B11111
};
byte custom7[] = {
 B00000,
 B00000,
 B11111,
 B11111,
 B11111,
 B11111,
 B11111,
 B11111
};
byte custom8[] = {
 B00000,
 B11111,
 B11111,
 B11111,
 B11111,
 B11111,
 B11111,
 B11111
};
byte custom9[] = {
 B11111,
 B11111,
 B11111,
 B11111,
 B11111,
 B11111,
 B11111,
 B11111
}; byte custom10[] = {
 B00000,
 B00000,
 B00000,
 B00000,
 B00000,
 B00000,
 B00000,
 B00000
};
byte custom11[] = {
 B01110,
 B01010,
 B01110,
 B00000,
 B00000,
 B00000,
 B00000,
 B00000
};
float solar = A0;
float boiler = A1;
float bufer = A2;
//const int plus = A4;
//const int menu = A5;
//const int minus = A6;
#define SolarToBoiler 10
#define BuferToBoiler 9
#define SolarToBufer 8

int state1 = 0;
int state2 = 0;
int state3 = 0;
/*LCD RS pin to digital pin 12
 LCD Enable pin to digital pin 11
 LCD D4 pin to digital pin 5
 LCD D5 pin to digital pin 4
 LCD D6 pin to digital pin 3
 LCD D7 pin to digital pin 2*/
int diferentHi = 4;
int diferentLo = 2;



void setup() {
 // put your setup code here, to run once:
 lcd.createChar(0, custom0);
 lcd.createChar(1, custom1);
 lcd.createChar(2, custom2);
 lcd.createChar(3, custom3);
 lcd.createChar(4, custom4);
 lcd.createChar(5, custom5);
 lcd.createChar(6, custom6);
 lcd.createChar(7, custom7);
 lcd.createChar(8, custom8);
 lcd.createChar(9, custom9);
 lcd.createChar(10, custom10);
 lcd.createChar(11, custom11);


 pinMode(A4, INPUT);
 pinMode(A5, INPUT);
 pinMode(A6, INPUT);
 pinMode(SolarToBoiler, OUTPUT);
 digitalWrite(SolarToBoiler, LOW);
 pinMode(BuferToBoiler, OUTPUT);
 digitalWrite(BuferToBoiler, LOW);
 pinMode(SolarToBufer, OUTPUT);
 digitalWrite(SolarToBufer, LOW);
 lcd.begin(16, 2);
 lcd.clear();
 lcd.setCursor(0, 0);

}

void loop() {
 delay(10);
 //if (state1 == 0){
 // lcd.clear();
 //SolarBoiler();
 //}


 if (digitalRead(A5) == LOW && state2 == 0) {
   lcd.clear();
   delay(50);
   state1 = 1;
   if (state1 == 1) {
     DiferentH();
     delay(120);
   }

 }
 if (digitalRead(A5) == LOW && state1 == 1) {
   lcd.clear();
   delay(50);
   state2 = 1;
   if (state2 == 1) {
     DiferentL();
     delay(120);
   }
 }
 if (digitalRead(A5) == LOW && state1 == 1 && state2 == 1) {
   lcd.clear();
   //delay(50);
   state2 = 0;
   //delay(50);
   state1 = 0;
   delay(120);
 }


}
void DiferentH() {

 lcd.clear();
 lcd.setCursor(0, 0);
 delay(50);
 lcd.print("DIFERENT HI ");
 lcd.print(diferentHi);
 lcd.write(byte(11));
 lcd.setCursor(0, 1);
 lcd.print("________________" );
 delay(50);
 if (digitalRead(A4) == LOW && diferentHi <= 20) {
   diferentHi++;
   delay(50);
 }


}

void DiferentL() {
 lcd.clear();
 lcd.setCursor(0, 0);
 delay(50);
 lcd.print("DIFERENT LOW ");
 lcd.print(diferentLo);
 lcd.write(byte(11));
 lcd.setCursor(0, 1);
 lcd.print("________________" );
 delay(50);
 if (digitalRead(A4) == LOW && diferentLo <= diferentHi + 2) {

   diferentLo++;
   delay(50);
 }
}
void SolarBoiler() {


 float tempSolar = analogRead(solar);
 tempSolar = map(tempSolar, 15, 1021, 0, 260);
 lcd.print("Solar  ");
 lcd.print(tempSolar);
 lcd.write(byte(11));
 lcd.print("C");
 float tempBoiler = analogRead(boiler);
 tempBoiler = map(tempBoiler, 15, 1021, 0, 260);
 lcd.setCursor(0, 1);
 lcd.print("Boiler ");
 lcd.print(tempBoiler);

 lcd.write(byte(11));
 lcd.print("C");
 float tempBufer = analogRead(bufer);

 delay(100);

 if ((tempSolar - tempBoiler) >= diferentHi ) {
   digitalWrite(SolarToBoiler, HIGH);
 }
 else if ((tempSolar - tempBoiler) <= diferentLo) {
   delay(1000);
   digitalWrite(SolarToBoiler, LOW);
 }



 if (digitalRead(SolarToBoiler) == HIGH) {
   Anime();
 }
}
void Anime() {
 //lcd.setCursor(15,0);
 //lcd.write(byte(0));
 delay(50);
 //lcd.setCursor(15,0);
 //lcd.write(byte(1));
 delay(50);

 lcd.setCursor(15, 1);
 lcd.write(byte(2));
 delay(50);
 //lcd.setCursor(15,1);
 //lcd.write(byte(3));
 lcd.setCursor(15, 1);
 lcd.write(byte(4));
 delay(50);
 lcd.setCursor(15, 1);
 lcd.write(byte(5));
 delay(50);
 lcd.setCursor(15, 1);
 lcd.write(byte(6));
 delay(50);
 lcd.setCursor(15, 1);
 lcd.write(byte(7));
 lcd.setCursor(15, 1);
 lcd.write(byte(8));
 delay(50);
 lcd.setCursor(15, 1);
 lcd.write(byte(9));
 delay(50);
 lcd.setCursor(15, 1);
 lcd.write(byte(10));
 delay(100);
}
[code]

]

Welcome,

I don't understand your question, but are you sure you can create 12 custom characters for your LCD ? Most of these LCD can only have 8 custom characters (which you can of course redefine as needed, so long as you don't need to display all custom characters at once).

To make it easy for people to help you please modify your post and use the code button </>
codeButton.png

so your code 
looks like this

and is easy to copy to a text editor. See How to use the Forum

Also please use the AutoFormat tool to indent your code consistently for easier reading.

Your code is too long for me to study quickly without copying to my text editor.

...R

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you tell us exactly what your project is please.

Thanks.. Tom... :slight_smile:

Image from Original Post so we don't have to download it. See this Simple Image Posting Guide

...R

longmarkoni:
I'm new to programming and I can't understand why the DiferentH function can't increase and decrease diferentHi

Thank you for putting your code in tags.

As you can probably see your image is almost unreadable - especially as you have not told us what it is intended to show.

Your Title "The function does not work on a differential thermostat." suggests to me that you are trying to use a code developed for one type of thermostat with a different type of thermostat. If that is the case please post a link to the datasheets for the two thermostats so we can study their technical differences.

...R

Thank you for the quick answers.
No code I wrote it and it is not finished.
When I tried the code I found that the function
void DiferentH () and DiferentL () do not change the value of the trim when called.
I don't know if the Proteus file was uploaded correctly.

New folder.zip (23.4 KB)

longmarkoni:
Hello.
I'm new to programming and I can't understand why the DiferentH function can't increase and decrease diferentHi

Well, it doesn't necessarily. It depends on this:

  if (digitalRead(A4) == LOW && diferentHi <= 20)

If A4 isn't low, it won't change diferentHi.

wildbill:
Well, it doesn't necessarily. It depends on this:

  if (digitalRead(A4) == LOW && diferentHi <= 20)

If A4 isn't low, it won't change diferentHi.

If exported, the function works.

longmarkoni:
If exported, the function works.

What does that mean?

Exported to where?

...R

Outside the function works.

Do you ever see this message printed?

lcd.print("DIFERENT HI ");

By the way, immediately get into the habit of assigning meaningful names to your variables and their values, e.g. "boilerHeaterState = ON" instead of just "state1 = 1". Otherwise your program is like a Mensa puzzle, an unnecessary challenge to decode.

You seem to have stepped backwards by removing some of that that was already in place:

//const int plus = A4;
...
  if (digitalRead(A4) == LOW && diferentHi <= 20)

which could have been

const int plusPin = A4;
...
  if (digitalRead(plusPin) == LOW && diferentHi <= 20)

Hi,
Can you post your schematic again please, but look in the CAD and you should be able to EXPORT the schematic as a jpg, this will make it easier to read and comprehend?

What is your project supposed to do?

Are you running this in simulation, or have you physically built it?

Have you got any bypass capacitors in your circuit and do you have any around the LM7805 regulator as per the suggested circuit in the LM7805 datasheet?

Thanks.. Tom... :slight_smile: