• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Sterownik kolektora w oparciu o Menu Backend
#1
Witam wszystkich użytkowników Arduino Polska Forum.

Jestem początkującym w temacie arduino, ze znalezionego w internetach kodu złożyłem sterownik do sterowania domowej roboty kolektorów. Wstawiłem kilka rzeczy tj wyświetlanie stopni celsjusza, zmiana wyświetlania na wyświetlaczu lcd 20x4. i dokonałem  zmian w położeniu wyników na ekranie. Poniżej wklejam kod do sprawdzenia i optymalizacji i tutaj prośba do znawców tematu o pomoc w optymalizacji kodu i zmiany układu menu. Mianowicie w originale układ pracuje w oparciu o klawiaturę drabinkową chciałbym zmienić sterowanie na układ 4 przyciskowy typu Up Down Enter Escape. Nie mogę dojść do ładu z kodem. Sad Jakieś  sugestie co zmienic i gdzie....pozdrawiam.

tutaj podaje kod

Kod:
//
/*
You are free:
to Share — to copy, distribute and transmit the work
to Remix — to adapt the work
Under the following conditions:
Attribution — You must attribute the work in the manner specified by the author or licensor
(but not in any way that suggests that they endorse you or your use of the work).
Noncommercial — You may not use this work for commercial purposes.
Share Alike — If you alter, transform, or build upon this work, you may distribute
the resulting work only under the same or similar license to this one.
All code is copyright Alvydas, alvydas (at) saulevire.lt (c)2014.

Features:
Keyboard temperatures are changed the pump on / off
Manual pump on/off
Storing values
Thermostat with cooling or heating function
LCD 16x2
changing LCD brightness
5 keys on the keyboard
The ability to connect a network controller ENC28J60
*/
//____________________________________________________________________________________//
// ********** Remove the comments in the right line ************************
#define PCB_VERSION 12 // PCB version v1.2 with Arduino Pro Mini
//#define PCB_VERSION 121 // PCB version v1.21 with Arduino Nano (CH340G usb to ttl chip)

#ifndef PCB_VERSION
#error "You must define PCB_VERSION in linee 26 or 27"
#endif

#if PCB_VERSION == 12
#define Key_Pin A7    // analog pin assigned for button reading
#define BackLight_Pin 9 //LCD backlight pin (standart LCD KeeyPad use pin 10)
#define ONE_WIRE_BUS1 2 // Collector
#define ONE_WIRE_BUS2 8 // Boiler
#define ONE_WIRE_BUS3 A3 // Thermostat
#else
#define Key_Pin A7    // analog pin assigned for button reading
#define BackLight_Pin 9 //LCD backlight pin (standart LCD KeeyPad use pin 10)
#define ONE_WIRE_BUS1 2 // Collector
#define ONE_WIRE_BUS2 8 // Boiler
#define ONE_WIRE_BUS3 A3 // Thermostat
#endif
#define DEBUGds18b20

//______________________________________________________________________________________//

#include <Wire.h>
 #include "MenuBackend.h"  
 // Thank wojtekizk, for example
 // http://majsterkowo.pl/forum/menubackend-jak-sie-w-nim-odnalezc-t1549.html
  #include <LiquidCrystal.h>         
 #include <OneWire.h>
#include <DallasTemperature.h>
 #include <EEPROM.h>
#include "definitions.h"

  // --- define their own characters for the LCD arrows: down, left, right, top and power
uint8_t arrowUpDown[8] = {0x4,0xe,0x15,0x4,0x15,0xe,0x4};
uint8_t arrowDown[8]  = {0x4,0x4,0x4,04,0x15,0xe,0x4};
uint8_t arrowRight[8] = {0x0,0x4,0x2,0x1f,0x2,0x4,0x0};
uint8_t arrowLeft[8] = {0x0,0x4,0x8,0x1f,0x8,0x4,0x0};
uint8_t arrowBack[8] = {0x1,0x1,0x5,0x9,0x1f,0x8,0x4};
uint8_t arrowUp[8]={B00100,B01110,B11111,B00100,B00100,B00100,B00100,B00100};
byte degree[8] ={B00110,B01001,B01001,B00110,B00000,B00000,B00000,B00000};
// definition pin for LCD (check the pins in your LCD)

    
LiquidCrystal lcd(A5, 3, 4, 5, 6, 7);
char *LCD_string_1;                      // 1 string text displayed on the LCD
char *LCD_string_2;                      // 2 string text displayed on the LCD
char *LCD_string_3;                      // 3 string text displayed on the LCD
char *LCD_string_4;                      // 4 string text displayed on the LCD
    boolean InMenu = false;
int freeRam () {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

MenuBackend menu = MenuBackend(menuUseEvent,menuChangeEvent); // menu design
   //                        ("                ")
      MenuItem P1 =  MenuItem("KOLEKTOR       ",1);
      MenuItem P11 = MenuItem("ROZNICA WL     ",2);
      MenuItem P12 = MenuItem("ROZNICA WYL"    ,2);
      MenuItem P13 = MenuItem("POMPA MANUALNA" ,2);

   MenuItem P2 = MenuItem("POMPA CO ",1);
      MenuItem P21 = MenuItem("USTAW TEMP. WL",2);
      MenuItem P22 = MenuItem("USTAW TEMP. WYL",2);
      MenuItem P23 = MenuItem("STAN        ",2);

   MenuItem P3 = MenuItem("USTAWIENIA      ",1);
      MenuItem P31 = MenuItem("ZAPISZ          ",2);
      MenuItem P32 = MenuItem("UST. FABRYCZNE  ",2);
      MenuItem P33 = MenuItem("JASNOSC LCD",2);


void menuSetup()                       
{
      menu.getRoot().add(P1);          
      P1.add(P11);
        P11.add(P12);P11.addLeft(P1);    
        P12.add(P13);P12.addLeft(P1);  //
        P13.add(P11);P13.addLeft(P1);  //
      menu.getRoot().add(P2);
      P1.addRight(P2);                 //
      
      P2.add(P21);                     //
        P21.add(P22);P21.addLeft(P2);  //
        P22.add(P23);P22.addLeft(P2);  //
        P23.add(P21);P23.addLeft(P2);  //
      menu.getRoot().add(P3);
      P2.addRight(P3);                 //
        
      P3.add(P31);                     //
        P31.add(P32);P31.addLeft(P3);  //
        P32.add(P33);P32.addLeft(P3);  //
        P33.add(P31);P33.addLeft(P3);  //
      menu.getRoot().add(P1);
      P3.addRight(P1);                 //
      
}
// -----------  -----------------------------------------------------------------------
void menuUseEvent(MenuUseEvent used)      
{
   Serial.print("pasirinkta:  "); Serial.println(used.item.getName());

/* __________________________Settings brithness __________________ */
  if (used.item.getName() == "LCD brightness")
  {
  lcd.setCursor(0,1);
  lcd.write(7);
  lcd.print("                  ");
  lcd.setCursor(1,1);
  lcd.print("JASNOSC");
  lcd.setCursor(12,1);
  lcd.print(LCD_brightness);
  lcd.print("0% ");
  lcd.write(7);
  int  action=-1;delay(1000);           
  while(action!=4)
{
Keyboard_change=-1;
action=Read_keyboard(Key_Pin);         
if(Keyboard_change!=action)            
{lcd.setCursor(12,1);
if (action==1) {LCD_brightness++;
analogWrite(BackLight_Pin,LCD_brightness*25);
delay(300);}
if (action==2)  {LCD_brightness--;
analogWrite(BackLight_Pin,LCD_brightness*25);
delay(300);}
if (LCD_brightness > 10)  LCD_brightness = 1;
if (LCD_brightness < 1)  LCD_brightness = 10;
if (LCD_brightness < 10) lcd.print(" ");
lcd.print(LCD_brightness);
if (LCD_brightness == 0) lcd.print("");
lcd.print("0% ");
if(action==4)
{
lcd.setCursor(0,0);
lcd.print(">JASNOSC OK");
lcd.setCursor(0,1);
lcd.print("                ");
menu.moveDown();
}
}
} Keyboard_change=action;
}
//////////////////////////////////////////////////////////////////
/* ______________________ SETTINGS Save _______________________ */
// Save to EEPROM
if (used.item.getName() == "Save          ")
{
SaveConfig();
lcd.setCursor(0,0);lcd.print(">ZAPISYWANIE OK     ")
;delay(2000); // show OK for 2 sec
lcd.setCursor(0,0);lcd.print("              ");
lcd.setCursor(0,0);lcd.print("*");
lcd.print(LCD_string_1);
lcd.setCursor(15,0);lcd.print("*");
menu.moveDown();
}
/////////////////////////////////////////////////////////////
/* __________________________ SETTINGS default ____________ */
// Save to EEPROM
if (used.item.getName() == "Set default   ")
{
lcd.setCursor(0,0);lcd.print(">UST. FABRYCZNE OK");
delay(2000);
lcd.setCursor(0,0);
lcd.print("              ");
lcd.setCursor(0,0);
lcd.print("*");
lcd.print(LCD_string_1);
lcd.setCursor(19,0);
lcd.print("*");
Pump_power_on_difference = 6;  
Pump_power_off_difference = 3;
temperature_1 = 20;  
temperature_2 = 25;
Thermostat_status = 3;                         // off
Manual_pump_status = false;
LCD_brightness = 5;                 
SaveConfig();
menu.moveDown();
}
////////////////////////////////////////////////////////////////////
/* __________________________ Collector   _______________________ */
//  ON - the difference between the temperature       
if (used.item.getName() == "Difference on ")    // exactly the same string "Difference on "
Pump_power_on_difference =  MeniuFunkcija ("Set=          ", Pump_power_on_difference, 25, 1, ">Diff T on  OK");
///////////////////////////////////////////////////////////////////
/* __________________________ Collector _______________________ */
// OFF - the difference between the temperature            
if (used.item.getName() == "Difference off")   // exactly the same string "Difference off"
Pump_power_off_difference =  MeniuFunkcija ("Set=          ", Pump_power_off_difference, 25, 1, ">Diff T off OK");
///////////////////////////////////////////////////////////////////     

/* __________________________ Collector Manual pump on ____________________________________ */
if (used.item.getName() == "Manual pump   ")
{       
lcd.setCursor(0,0);
lcd.write(7);     
lcd.setCursor(1,1);
lcd.print("POMPA MANUALNA");
if (Manual_pump_status == true) lcd.print("-WL"); //
if (Manual_pump_status == false) lcd.print("-WYL"); //
int  action=-1; delay(1000);         //
while(action!=4)                   //
{
Keyboard_change=-1;
action=Read_keyboard(Key_Pin); //delay(300);  
if(Keyboard_change!=action)           
{
if(action==2) {Manual_pump_status = false;
lcd.setCursor(8,1);
lcd.print("WYL    ");
delay(200);
}
if(action==1) {Manual_pump_status = true;  
lcd.setCursor(8,1);
lcd.print("WL     ");
delay(200);}
if(action==4) // 0
{
lcd.setCursor(0,0);
lcd.print(">POMPA MANUALNA OK");
delay(2000); // 0
lcd.setCursor(0,0);
lcd.print("              ");
lcd.setCursor(1,0);
lcd.print(LCD_string_1);          
menu.moveDown();
}
}
} Keyboard_change=action;
 }
/* __________________________ Termostat temperature 1   _______________________ */
if (used.item.getName() == "temperature 1 ")   // exactly the same string "temperature 1 "
temperature_1 =  MeniuFunkcija ("Set t1=       ", temperature_1, 99, -25, ">Temperatura OK");
     ///////////////////////////////////////////////////////////////////
/* __________________________ Termostat temperature 2  _______________________ */     
if (used.item.getName() == "temperature 2 ")   // exactly the same string "temperature 2 "
temperature_2 =  MeniuFunkcija ("Set t2=       ", temperature_2, 99, -25, ">Temperatura OK");
     ///////////////////////////////////////////////////////////////////     
/* __________________________ Termostat status  _______________________ */     
if (used.item.getName() == "Status        ")
{       
lcd.setCursor(0,0);
lcd.write(7);     
lcd.setCursor(1,1);
lcd.print("STAN-");
if (Thermostat_status == 1) lcd.print("heating"); // heating
if (Thermostat_status == 2) lcd.print("freezing"); // freezing
if (Thermostat_status == 3) lcd.print("WYL"); // turned off
int  action=-1; delay(1000);
while(action!=4)
{
Keyboard_change=-1;
action=Read_keyboard(Key_Pin); //delay(300);  
if(Keyboard_change!=action)           
{
if (action==1) {Thermostat_status++; if(Thermostat_status>3) Thermostat_status=1;
lcd.setCursor(6,3);
if (Thermostat_status == 1) lcd.print("GRZANIE "); // heating
if (Thermostat_status == 2) lcd.print("freezing"); // freezing
if (Thermostat_status == 3) lcd.print("WYL    "); // turned off
delay(200);}
if(action==2)  {Thermostat_status--;
if(Thermostat_status<1) Thermostat_status=3;
lcd.setCursor(6,3);
if (Thermostat_status == 1) lcd.print("heating "); // heating
if (Thermostat_status == 2) lcd.print("freezing"); // freezing
if (Thermostat_status == 3) lcd.print("WYL    "); // turned off
delay(200);}
if(action==4)
{
lcd.setCursor(0,0);
lcd.print(">STAN OK");
delay(2000);
lcd.setCursor(0,0);
lcd.print("              ");
lcd.setCursor(1,0);
lcd.print(LCD_string_1);
menu.moveDown();
}
}
} Keyboard_change=action;
}
}
// --- Reakcja na wci�ni�cie klawisza -----------------------------------------------------------------
void menuChangeEvent(MenuChangeEvent changed)  // funkcja klasy MenuBackend
{
if(changed.to.getName()==menu.getRoot())
{
InMenu =false;
Serial.println("Now we are on MenuRoot");
LCD_T_template();
Temperature_Imaging();
}
int c=changed.to.getShortkey();                         // shortkey charge (1,2,3, or 4)
lcd.clear();                                            // clear lcd
lcd.setCursor(0,0);
if(c==1)                                                // If this menu Main contacts (shortkey = 1) are:
{InMenu =true;
lcd.write(3);                                         // Left arrow
strcpy(LCD_string_1,changed.to.getName());            // Create a string in the first line
lcd.print(LCD_string_1);                              // Display it
lcd.setCursor(19,0);lcd.write(4);                     // Right arrow
lcd.setCursor(0,1);lcd.write(5);                      // Down arrow
lcd.setCursor(19,1);lcd.write(5);                     // Right arrow
lcd.setCursor(0,1);lcd.write(5);                      // Down arrow


}
if(c==2)                                              // if the submenu for the child - (shortkey = 2) are:
{InMenu =true;
lcd.print("*");                                       // draw a star
strcpy(LCD_string_2,changed.to.getName());            // create a string in the first line
lcd.print(LCD_string_1);                              // print it
    lcd.setCursor(19,0);lcd.print("*");                   // draw a star
    lcd.setCursor(0,1);lcd.write(6);                      // the second line and arrow return (arrowBack)
    lcd.print(changed.to.getName());                      // display name of "child"
    lcd.setCursor(19,1);lcd.write(7);                     // arrow up-down
    }
    if(c==3)                                              // if the child has a child - (shortkey = 3) are:
    {InMenu =true;
    lcd.print("*");                                       // draw a star
    strcpy(LCD_string_2,changed.to.getName());            // the name of the menu options to the variable line 2
    lcd.print(LCD_string_1);                              // and display the first line of
    lcd.setCursor(19,0);lcd.print("*");                   // draw a star
    lcd.setCursor(0,1);lcd.write(6);                      // the second line and arrow arrowBack
    lcd.print(changed.to.getName());                      // display the grandson of the second line
    lcd.setCursor(19,1);lcd.write(4);                     // arrow to the right because they are the grandchildren
    }
    
    if(c==4)                                              // if grandchild (shortkey = 4) are:
    {InMenu =true;
    lcd.print("*");                                       // draw a star
    lcd.print(LCD_string_2);                              // in the first line of the display child (or parent grandchild)
    lcd.setCursor(19,0);lcd.print("*");                   // draw a star
    lcd.setCursor(0,1);lcd.write(6);                      // the second line and arrow arrowBack
    lcd.print(changed.to.getName());                      // display grandson
    lcd.setCursor(19,1);lcd.write(7);                     // arrow up-down
    }
}

// --- 5 analog buttons keyboard scan version DFRobot --------------------------------------
volatile int Read_keyboard(int analog)
{
   int stan_Analog = analogRead(analog);delay(30);//Serial.println(stan_Analog);
   if (stan_Analog > 1000) return -1; // limit
   if (stan_Analog < 50)   return 3;  // right
   if (stan_Analog < 200)  return 1;  // up
   if (stan_Analog < 400)  return 2;  // down
   if (stan_Analog < 600)  return 0;  // left
   if (stan_Analog < 800)  return 4;  // OK
   return -1;                         // Not pressed
}
// ============================================================================================
//
void setup()
{
 LoadConfig();

/* ********************************************************* */

  pinMode(BackLight_Pin, OUTPUT);
  digitalWrite(BackLight_Pin,HIGH);
  analogWrite(BackLight_Pin,LCD_brightness*25);
  LCD_string_1=new char[20];
  LCD_string_2=new char[20];
  LCD_string_3=new char[20];
  LCD_string_4=new char[20];
 
                        
  Serial.begin(9600);   
  lcd.begin(20, 4);    
  lcd.clear();
  lcd.createChar(3,arrowLeft);    // LCD symbol left
  lcd.createChar(4,arrowRight);
  lcd.createChar(5,arrowDown);
  lcd.createChar(6,arrowBack);
  lcd.createChar(7,arrowUpDown);
  lcd.createChar(1,arrowUp);
  lcd.createChar(1, degree);
 
lcd.setCursor(0,0);
flashbacklight();
lcd.print("STEROWNIK KOLEKTOROW");
lcd.setCursor(0,1);
lcd.print("     SLONECZNYCH    ");
lcd.setCursor(0,2);
lcd.print("       PELNA        ");
lcd.setCursor(0,3);
lcd.print("     CHATA 2016     ");
delay(3799);
lcd.clear();
Collector_sensor.begin();
Boiler_sensor.begin();
Thermostat_sensor.begin();
   
pinMode(13,OUTPUT);digitalWrite(13,LOW); // only for test
pinMode(Relay_Collector,OUTPUT);pinMode(Relay_Thermostat,OUTPUT);
digitalWrite(Relay_Collector,HIGH);digitalWrite(Relay_Thermostat,HIGH);
 menuSetup();
//  menu.moveUp();      
Temperature_measurements_1();
LCD_T_template();
//  Temperature_Imaging();
LCD_switching_on_Time = millis();
temperature_measurement_time_1 = millis();
}  

//************ END **************//
// ************************ START void loop() *******************************
void loop()    
{
// measured temperature specified time intervals (Temperature_measurement_interval)
/* +++++++++++++++++++++++++++ First level ++++++++++++++++++++++++++++++++++++ */
if (millis() > temperature_measurement_time_1 ) {
  temperature_measurement_time_1 = millis() + Temperature_measurement_interval_1;
  Temperature_measurements_1();}

    
  // if the screen, without application of the button illuminates more than the tasks, backlight off
      if (millis()- LCD_switching_on_Time > The_LCD_light_Break) {
      analogWrite(BackLight_Pin, 0);
       pinMode(13,OUTPUT);digitalWrite(13,LOW); // only for test
      Backlighting = false;
      LCD_switching_on_Time = millis();}
 // When you press any key, the screen backlight is turned on when it is turned off
if ((x != -1) && (Backlighting == false)){ analogWrite(BackLight_Pin,lcd_backlight*25);
                                            digitalWrite(13,HIGH); // only for test
                                            Backlighting = true;}

// If the menu is inactive for some time, it returns to the main program
//if ((x != -1) && (InMenu == true))Menu_time_spent_inactive = millis();
//    else {if (millis()- Menu_time_spent_inactive > inactive_menu)
//          menu.toRoot();
//}
  x=Read_keyboard(Key_Pin);delay(30);             // read the state of the keyboard:
  if(Keyboard_change!=x)                               // if there was a change in the state are:
    {
      switch(x)                           // check what was pressed
      {
      case 0: menu.moveRight();break;     // If pressed, move it in the right menu to the right
      case 1: menu.moveUp();break;        // Menu to top
      case 2: menu.moveDown();break;      // Menu Down
      case 3: menu.moveLeft();break;      // Menu to the left
      case 4: menu.use();break;           // pressed OK, so jump to the function menuUseEvent (MenuUseEvend used)
                                          // This function is just serve our menu, check here
                                          // Which option is selected, and here we create the code to the event handler.
      }
    } Keyboard_change=x;                 //Assign the value of x variable amended so that the long pressing the
                                         // Same key did not result in the re-generation event.
                                         // Program responds to a change in the keyboard.
// If you are not currently within the menu is of a continuous program
if (InMenu == false){
  // time interval used for the LCD refresh
  if (millis() > LCD_Update_Time ) {
  LCD_Update_Time = millis() + LCD_Update_Interval;
  LCD_T_template();
  Temperature_Imaging();

  //#ifdef DEBUGds18b20
//Serial.println("Temperate_measurement");
//unsigned long start = millis();
//#endif
 
#ifdef DEBUGds18b20
//unsigned long stop = millis();
//Serial.print("Temperature measurement time: ");  Serial.println(stop - start);
Serial.print("K/ ");Serial.print(K);Serial.print(" B/ ");Serial.print(B);Serial.print(" T/ ");Serial.println(T);
Serial.println("----");
Serial.print("Thermostat_status- ");Serial.println(Thermostat_status);
Serial.print("temperature_1- ");Serial.print(temperature_1);
Serial.print("  temperature_2- ");Serial.println(temperature_2);
Serial.println("----");
Serial.print("Pump_power_on_difference- ");Serial.print(Pump_power_on_difference);
Serial.print("  Pump_power_off_difference- ");Serial.println(Pump_power_off_difference);

Serial.print("millis- ");Serial.println(millis()/1000);
Serial.println(freeRam());
#endif
  }
}


//------------------ collector pump and thermostat control -----------------------//
if (millis() > Relay_switching_time )
 {
   Relay_switching_time=millis()+Relay_switching_interval;
if (Manual_pump_status == true) {digitalWrite(Relay_Collector,LOW);}
else{
   if (K-B>=Pump_power_on_difference) digitalWrite(Relay_Collector,LOW);
   if (K-B<=Pump_power_off_difference) digitalWrite(Relay_Collector,HIGH);
    }
  if (Thermostat_status == 1)
   {// If the heating mode (Thermostat_status = 1)
    if (T <= temperature_1) digitalWrite(Relay_Thermostat,LOW);  
    if (T >= temperature_2) digitalWrite(Relay_Thermostat,HIGH);
   }
   if (Thermostat_status == 2)
    {// If the freezing mode (Thermostat_status = 2)
     if (T >= temperature_1) digitalWrite(Relay_Thermostat,LOW);  
     if (T <= temperature_2) digitalWrite(Relay_Thermostat,HIGH);
    }
    if (Thermostat_status == 3)
     // If you do not need a second relay-mode off
      digitalWrite(Relay_Thermostat,HIGH);
 }
}// === END ===========================================================
void Temperature_measurements_1(){
  //____________________________ Start Sensor 1 _________________________________
#ifdef SetWaitForConversionFALSE
  Collector_sensor.setWaitForConversion(false);  // makes it async
#endif
  Collector_sensor.requestTemperatures(); // Send the command to get temperatures
  K=Collector_sensor.getTempCByIndex(0);
//_____________________________ Stop Sensor 1 ___________________________________
  //______________________ Start Sensor 3 ________________________________________
  #ifdef SetWaitForConversionFALSE
  Thermostat_sensor.setWaitForConversion(false);  // makes it async
#endif
  Thermostat_sensor.requestTemperatures(); // Send the command to get temperatures
T=Thermostat_sensor.getTempCByIndex(0);
//___________________ Stop Sensor 3 ______________________________________________
//__________________________________________ Start Sensor 2 _____________________
#ifdef SetWaitForConversionFALSE
  Boiler_sensor.setWaitForConversion(false);  // makes it async
#endif
  Boiler_sensor.requestTemperatures(); // Send the command to get temperatures
  B=Boiler_sensor.getTempCByIndex(0);
//_____________________________________ Stop Sensor 2 ____________________________
}
void LCD_T_template(){
//  analogWrite(BackLight_Pin,LCD_brightness*25);
 
  lcd.setCursor(0,0);
  lcd.print("KOLEKTOR");
  lcd.setCursor(13,0);
  lcd.print((char)223);
  lcd.setCursor(15,0);
  lcd.print("R");
  lcd.setCursor(0,1);
  lcd.print("BOILER-A");
  lcd.setCursor(13,1);
  lcd.print((char)223);
  lcd.setCursor(0,2);
  lcd.print("BOILER-B");
  lcd.setCursor(13,2);
  lcd.print((char)223);
  lcd.setCursor(0,3);
  lcd.print("P-CO");
 

}

void Temperature_Imaging(){
lcd.setCursor(9,0);
lcd.print(K,1);
if (K-B>0)
{lcd.setCursor(16,0);
lcd.print("+");
lcd.print((K-B),1);}
else {lcd.setCursor(16,0);
lcd.print((K-B),1);}
if (K-B>=Pump_power_on_difference)  
{lcd.setCursor(9,3);
lcd.print("C");
lcd.write(1);}  
if (K-B<=Pump_power_off_difference)
{lcd.setCursor(9,3);
lcd.print("P-CW");
lcd.write(5);}  
                                             
lcd.setCursor(9,1);
lcd.print(B,1);
lcd.setCursor(9,2);
lcd.print(T,1);//(int(K + 0.5));
if (Thermostat_status == 1) {// If the heating mode (Thermostat_status = 1)
if (T <= temperature_1)
{lcd.setCursor(14,3);
lcd.print("H");
lcd.write(1);}  
if (T >= temperature_2)
{lcd.setCursor(14,3);
lcd.print("H");
lcd.write(5);}
}
if (Thermostat_status == 2)
{// If the freezing mode (Thermostat_status = 2)
if (T >= temperature_1)
{lcd.setCursor(14,3);
lcd.print("F");
lcd.write(1);}  
if (T <= temperature_2)
{lcd.setCursor(14,3);
lcd.print("F");
lcd.write(5);}  
    }
if (Thermostat_status == 3)
{lcd.setCursor(5,3);
lcd.print("WYL");}
}
int MeniuFunkcija (String text_1, int  Converted_Value, int Max_Value, int Min_Value, String text_2)
            {
        lcd.setCursor(0,0);lcd.write(7);     
        lcd.setCursor(1,1);lcd.print(text_1); //("Nustatyta=   ");
        lcd.setCursor(11,1);lcd.print( Converted_Value); // shows the current value
        int  action=-1; delay(1000);         //
                                           
        while(action!=4)                   //
         {
           Keyboard_change=-1;
           action=Read_keyboard(Key_Pin); //delay(300);  
                                            
if(Keyboard_change!=action)           
{
if (action==1) { Converted_Value++;
if( Converted_Value>Max_Value)  Converted_Value=Max_Value;
lcd.setCursor(11,1);
if( Converted_Value<10) lcd.print(" ");
lcd.print( Converted_Value);
delay(200);}
if(action==2)  { Converted_Value--;
if( Converted_Value<Min_Value)  Converted_Value=Min_Value;
lcd.setCursor(11,1);
if( Converted_Value<10) lcd.print(" ");
lcd.print( Converted_Value);
delay(200);}
if(action==4)
{
lcd.setCursor(0,0);
lcd.print(text_2);
delay(2000);
lcd.setCursor(0,0);
lcd.print("                ");
lcd.setCursor(0,0);
lcd.print("*");
lcd.print(LCD_string_1);
lcd.setCursor(15,0);
lcd.print("*");
 menu.moveDown();
}
}
} Keyboard_change=action;                   // Keyboard_change update, in order to react only Keyboard_change keyboard status
                                            // This is an important moment - while loop ends and turn the control to the main loop loop ()
return  Converted_Value;                    // Scan settings
}
boolean LoadConfig(){
if((EEPROM.read(0) == 27) && (EEPROM.read(1) == 28) &&  
   (EEPROM.read(2) == 13) && (EEPROM.read(3) == 18)) {
if (EEPROM.read(4) == EEPROM.read(5)) Pump_power_on_difference = EEPROM.read(4);  
if (EEPROM.read(6) == EEPROM.read(7)) Pump_power_off_difference = EEPROM.read(6);
if (EEPROM.read(8) == EEPROM.read(9)) temperature_1 = EEPROM.read(8);  
if (EEPROM.read(10) == EEPROM.read(11)) temperature_2 = EEPROM.read(10);
if (EEPROM.read(12) == EEPROM.read(13)) Thermostat_status = EEPROM.read(12);
if (EEPROM.read(14) == EEPROM.read(15)) LCD_brightness = EEPROM.read(14);
return true;
}
  return false;
}
// Write settings
void SaveConfig(){
  EEPROM.write(0,27);
  EEPROM.write(1,28);
  EEPROM.write(2,13);
  EEPROM.write(3,18);
  EEPROM.write(4,Pump_power_on_difference);EEPROM.write(5,Pump_power_on_difference);  //
  EEPROM.write(6,Pump_power_off_difference); EEPROM.write(7,Pump_power_off_difference);  //
  EEPROM.write(8,temperature_1);EEPROM.write(9,temperature_1);  //
  EEPROM.write(10,temperature_2); EEPROM.write(11,temperature_2);  //
  EEPROM.write(12,Thermostat_status); EEPROM.write(13,Thermostat_status);  //
  EEPROM.write(14,LCD_brightness); EEPROM.write(15,LCD_brightness);  //
}
void flashbacklight() {
  digitalWrite(BackLight_Pin, LOW);  delay(150);
  digitalWrite(BackLight_Pin, HIGH); delay(150);
}
 
Za wszelkie sugestie bardzo dziekuje.
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości