Insertar un sheck dentro de otro (bigreloj & control riego

Hola,buenos días y espero que los reyes se hallan portado bien.

Me remito a ustedes una vez más y ahora espero haber puesto el tema en el foro español, como expongo en el hilo,tengo dos sketsh, uno de un reloj con números grandes y otro de un controlador de riego.
El controlador tiene su propio reloj y está basado en el DS3231,antes tenía otro,pero he podido adaptado,también tenía para poder controlarlo con Souliss ,también adaptado para borrar esa opción ya que al ser más antigua las librerías este no compilaba.

La cosa es que cuando he intentado unir el big reloj con el controlador,me surgen algunos problemas.

La compilación esta bien,,compila, pero :
se solapa información.
El intento de botones no me sale y da errores

Lo que quiero hacer es que en la pantalla de inicio del control riego, esté primeramente el bigreloj y cambie a la pantalla principal del control riego cuando se aprieta un boton del keypad 4x4.
No consigo hacer esa función por más que he mirado de otros proyectos y dado mil vueltas al codigo,se siguen solapando y aveces con tanto intento hasta con caracterres raros.

El sketch del controlador es de:
ejmloureiro77.blogspot.com, de él y sus compañeros es el merito, yo tan sólo con su permiso lo he modificado.
El sketch del bigreloj esta sacado del foro

Les dejo los dos sketch originales y el que estoy modificando para si pueden indicarme que cambios he de hacer.
gracias de antemano

sketch Big Reloj:

//**************************************************************************************************
//                                 BIG FONT (4-line) LCD CHARACTERS
//                                   Adrian Jones, February 2015
//
//**************************************************************************************************

// Build 1
//   r1 150214 - initial build with glyphs and big font character table in program memory
//   r2 150227 - added RTC support
//********************************************************************************************
#define build 1
#define revision 2
//********************************************************************************************

#include <avr/pgmspace.h>            // for memory storage in program space
#include <Wire.h>
#include <LiquidCrystal_I2C.h>       // library for I@C interface



LiquidCrystal_I2C lcd(0x27, 20, 4);
//Pins for the LCD are SCL A5, SDA A4

const char custom[][8] PROGMEM = {
  {0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0F, 0x1F},      // char 1: bottom right triangle
  {0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F},      // char 2: bottom block
  {0x00, 0x00, 0x00, 0x00, 0x10, 0x1C, 0x1E, 0x1F},      // char 3: bottom left triangle
  {0x1F, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00},      // char 4: top right triangle
  {0x1F, 0x1E, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00},      // char 5: top left triangle
  {0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00},      // char 6: upper block
  {0x1F, 0x1F, 0x1E, 0x1C, 0x18, 0x18, 0x10, 0x10}       // char 7: full top right triangle
  // room for another one!
};

const char bn[][30] PROGMEM = {                             // organized by row
  //         0               1               2               3               4              5               6                7               8               9
  {0x01, 0x02, 0x03, 0x01, 0x02, 0xFE, 0x01, 0x02, 0x03, 0x01, 0x02, 0x03, 0x02, 0xFE, 0x02, 0x02, 0x02, 0x02, 0x01, 0x02, 0x03, 0x02, 0x02, 0x02, 0x01, 0x02, 0x03, 0x01, 0x02, 0x03},
  {0xFF, 0xFE, 0xFF, 0xFE, 0xFF, 0xFE, 0x01, 0x02, 0xFF, 0xFE, 0x02, 0xFF, 0xFF, 0x02, 0xFF, 0xFF, 0x02, 0x02, 0xFF, 0x02, 0x03, 0xFE, 0x01, 0x07, 0xFF, 0x02, 0xFF, 0xFF, 0xFE, 0xFF},
  {0xFF, 0xFE, 0xFF, 0xFE, 0xFF, 0xFE, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFE, 0xFE, 0xFF, 0xFE, 0xFE, 0xFF, 0xFF, 0xFE, 0xFF, 0xFE, 0xFF, 0xFE, 0xFF, 0xFE, 0xFF, 0x04, 0x06, 0xFF},
  {0x04, 0x06, 0x05, 0xFE, 0x06, 0xFE, 0x06, 0x06, 0x06, 0x04, 0x06, 0x05, 0xFE, 0xFE, 0x06, 0x04, 0x06, 0x05, 0x04, 0x06, 0x05, 0xFE, 0x06, 0xFE, 0x04, 0x06, 0x05, 0xFE, 0xFE, 0x06}
};

byte col, row, nb = 0, bc = 0;                            // general
byte bb[8];                                               // byte buffer for reading from PROGMEM

//***********
#include <RTClib.h>
//RTC_Millis RTC;
RTC_DS3231 RTC;
byte hr, mn, se, osec;


//*****************************************************************************************//
//                                      Initial Setup
//*****************************************************************************************//
void setup() {
  randomSeed(analogRead(0));
  RTC.begin();
  // RTC.begin(DateTime(__DATE__, __TIME__));  // lee la hora del rtc

  lcd.init();
  lcd.backlight();
  for (nb = 0; nb < 7; nb++ ) {                 // create 8 custom characters
    for (bc = 0; bc < 8; bc++) bb[bc] = pgm_read_byte( &custom[nb][bc] );
    lcd.createChar ( nb + 1, bb );
  }

}

//*****************************************************************************************//
//                                      MAIN LOOP
//*****************************************************************************************//
void loop() {
  DateTime now = RTC.now();
  hr = now.hour() % 12 ;
  mn = now.minute();
  se = now.second();
  if (se != osec) {
    printNum(hr / 10, 0);
    printNum(hr % 10, 3);
    printColon(6);
    printNum(mn / 10, 7);
    printNum(mn % 10, 10);
    printColon(13);
    printNum(se / 10, 14);
    printNum(se % 10, 17);
    osec = se;
  }
  delay(50);                // not strictly necessary
}


// ********************************************************************************** //
//                                      SUBROUTINES
// ********************************************************************************** //
void printNum(byte digit, byte leftAdjust) {
  for (row = 0; row < 4; row++) {
    lcd.setCursor(leftAdjust, row);
    for (col = digit * 3; col < digit * 3 + 3; col++) {
      lcd.write(pgm_read_byte( &bn[row][col]) );
    }
  }
}

void printColon(byte leftAdjust) {
  for (row = 0; row < 4; row++) {
    lcd.setCursor(leftAdjust, row);
    if (row == 1 || row == 2) lcd.print(F(".")); else lcd.print(F(" "));
  }
}
// ********************************************************************************** //
//                                      OPERATION ROUTINES
// ********************************************************************************** //
// FREERAM: Returns the number of bytes currently free in RAM
int freeRam(void) {
  extern int  __bss_end, *__brkval;
  int free_memory;
  if ((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end);
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval);
  }
  return free_memory;
}

sketch controlador:

//---------------------------------------------------
// 2.     Include framework code and libraries
//---------------------------------------------------

#include <Wire.h>                 //I2C DS1307 RTC
#include <LiquidCrystal_I2C.h>    //lcd IIC
#include <Keypad.h>
#include <SPI.h>
#include <Sodaq_DS3231.h>//rtc ds3231
#include <EEPROMex.h>
#include <EEPROMVar.h>

//----------------------------------------------------
// 5. Pines
//----------------------------------------------------
//pin 18 serial1 rx
//pin 19 serial1 rx
//Pin20 SDA IIC reloj+lcd iic
//Pin21 SCL IIC reloj+lcd iic
#define pinS1   22 //pin para relé sector de riego 1
#define pinS2   24
#define pinS3   26
#define pinS4   28
#define pinS5   30
#define pinS6   32
#define pinS7   34
#define pinPump 36 //pin para relé que activa bomba conectado Normalmente Abierto

//--keypad-------------------------------------------
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
//----------------------------------------------------
// 6. Variables
//----------------------------------------------------
//-------------keypad
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
int horaAc;// Hora actual en minutos (0 a 1440)
char key;
char lastKey;
char resetKey;//xKey

char buffer[5];
int index = 0;
int pos = 0;

int progRec [8][16];//index, on/off, Inv?, Tr, h1,m1...h6,m6 eprom
int progCon [8][16];//index, ON/OFF, Inv?, Tr, "h ini 1","h final 1",.... "h ini 6","h final 6"
bool IO = 1;//ON/OFF programador
int mNivel1 = 0; //menu nivel 1
int mNivel2 = 0; //menu nivel 2
bool exiT = 0; //sale modo edicion
bool arrayS[8];//control, bomba
bool arrayS2[8];//control, horario+condicionantes
bool arraySActivo[8];//control, horario
int EPROMcount;
int arrayAM[8] = {0, 0, 0, 0, 0, 0, 0, 0}; //arranque manual"horaAC"
int arrayTAM[8] = {0, 0, 0, 0, 0, 0, 0, 0}; //Tiempo en arranque manual
int pinArray[8] = {0, pinS1, pinS2, pinS3, pinS4, pinS5, pinS6, pinS7};
int del = 0; //riego exterior suspendido x horas
int porc = 100; //porcentaje aplicado al tiempo de riego
int lastHour = 0;
int lastSecond = 0;
int timer = 0;
char iH[ ] = "  :  "; //usado en set hora
int ihh, imm;
int s = 1; //usado en set prog

byte cCount;//contador de ciclos
bool neW;
//----------------------------------------------------
// 7. Objetos
//----------------------------------------------------
DateTime now;
LiquidCrystal_I2C lcd(0x27, 20, 4);
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad
//DateTime dt(2011, 11, 10, 15, 18, 0, 5);
// =====================================================================================
// SETUP
// =====================================================================================
void setup() {

  rtc.begin();
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 1);
  lcd.print("V.1");
  lcd.noBacklight();

  pinMode(pinPump, OUTPUT);
  digitalWrite(pinPump, HIGH); //para que los reles chinos comiencen apagados
  digitalWrite(pinS1, HIGH);
  pinMode(pinS1, OUTPUT);
  digitalWrite(pinS2, HIGH);
  pinMode(pinS2, OUTPUT);
  digitalWrite(pinS3, HIGH);
  pinMode(pinS3, OUTPUT);
  digitalWrite(pinS4, HIGH);
  pinMode(pinS4, OUTPUT);
  digitalWrite(pinS5, HIGH);
  pinMode(pinS5, OUTPUT);
  digitalWrite(pinS6, HIGH);
  pinMode(pinS6, OUTPUT);
  digitalWrite(pinS7, HIGH);
  pinMode(pinS7, OUTPUT);
  DateTime now = rtc.now();
  horaAc = now.hour() * 60 + now.minute();
  EEPROM.setMemPool(0, EEPROMSizeMega);
  eepromRead();
}
// =====================================================================================
// LOOP
// =====================================================================================
void loop() {
  cCount++;
  if (cCount > 20) {
    cCount = 0;
  }
  now = rtc.now();
  horaAc = now.hour() * 60 + now.minute();
  if (horaAc == 0) { //resetea el array arranque manual a las 00:00
    arrayAM[8] = (0, 0, 0, 0, 0, 0, 0, 0);
  }
  if (now.hour() != lastHour) { //resta una hora a la variable de suspensión
    if ((del > 0) && (del < 73)) {
      del = del - 1;
    }
    lastHour = now.hour();
  }

  syncProg();
  menu();

  //control sectores
  for (int i = 1; i < 8; i++) {
    sectorActivo(i);
  }
  for (int i = 1; i < 8; i++) {
    //si ON y app o programa o arranque manual
    if (IO && ( arraySActivo[8 - 1] || (arrayS2[i]) || (arrayAM[i] > horaAc))) {
      //0x23 app
      digitalWrite(pinArray[i], LOW);
      arrayS[i] = 1;
    } else {
      digitalWrite(pinArray[i], HIGH);
      arrayS[i] = 0;
    }
  }//for
  //control bomba
  if (arrayS[1] || arrayS[2] || arrayS[3] || arrayS[4] || arrayS[5] || arrayS[6] || arrayS[7]) { //control bomba
    digitalWrite(pinPump, LOW);
    lcd.backlight();
  } else {
    digitalWrite(pinPump, HIGH);
  }
  //control lcd.backlight
  if (now.second() != lastSecond) {
    timer++;
    lastSecond = now.second();
  }
  if (timer > 60 && !(arrayS[1] || arrayS[2] || arrayS[3] || arrayS[4] || arrayS[5] || arrayS[6] || arrayS[7])) {
    lcd.backlight();// lcd.noBacklight();
  } else {
    lcd.backlight();
  }
  if (timer > 90) {
    mNivel1 = 0; //vuelve a pantalla de inicio tras 90s de inactividad
  }
  if (timer > 1000) {
    timer = 91; //32k
  }

}
// =====================================================================================
// Fin de LOOP
// =====================================================================================
void sectorActivo(int g) {
  //compruebo HORARIO y CONDICIONANTES
  //HORARIO: si hora !0:0 y TR!=0 y horario
  arraySActivo[g] = 0;
  for (int i = 4; i < 15; i += 2) {
    if (((progCon[g][i]) != 0) && ((progCon[g][3]) != 0) && (horaAc >= (progCon[g][i])) && (horaAc < (progCon[g][i + 1]))) {
      arraySActivo[g] = true;
    } else {
      if (!arraySActivo[g]) {
        arraySActivo[g] == false;
      }
    }
  }//for
  //CONDICIONANTES:riega si (invernadero y hora) o (!invernadero y !suspension y hora)
  if (((progCon[g][2]) && (arraySActivo[g])) || ((!(progCon[g][2])) && (!del) && (arraySActivo[g]))) {
    arrayS2[g] = true;
  }
  else {
    arrayS2[g] = false;
  }
}
void menu() {
  switch (mNivel1) {
    case 0:
      mainMenu(); //Hora etc
      break;
    case 1:
      manS();  //ARRANQUE MANUAL
      break;
    case 2:
      manS2();  //ARRANQUE MANUAL 2
      break;
    case 3:
      Delay();//RAIN DELAY, Suspender riego exterior(no invernadero) 6.12.24.48h
      break;
    case 4:
      setPorc();//PORCENTAJE DE RIEGO
      break;
    case 5:
      setHora ();//PONE EN HORA
      break;
    case 6:
      setProg ();//PROGRAMA
      break;
    case 7:
      borraP ();//BORRA PROGRAMACION
      break;
  }
}
//---------------------------------------------------------
//  Pantalla de INICIO                                  000
//---------------------------------------------------------
void mainMenu() {
  if (!cCount || !neW) {
   // lcd.clear();
    neW = 1;
  }
  lcd.noBlink();
  lcd.setCursor(0, 0);
  if (IO) {
    lcd.print("<C<<<< INICIO >>>>D>");
  }
  if (!IO) {
    lcd.print("<C< # Activar # >D>");
  }
  if (now.hour() > 9) lcd.setCursor(0, 1);
  if (now.hour() < 10) lcd.setCursor(1, 1);
  lcd.print(now.hour()%12, DEC);
  printDigits(now.minute());
  printDigits(now.second());
  
  lcd.setCursor(9, 1);
  lcd.print(int(rtc.getTemperature()));
  lcd.print(char(223));//imagenes google "char lcd"
  lcd.print("C");
  lcd.setCursor(14, 1);
  if (IO) {
    lcd.print("Activo");
  }
  if (!IO) {
    lcd.print("OFF OFF");
  }

  if (timer & 0x01) { //comprueba si es par
    lcd.setCursor(0, 2);

    if (arrayAM[1] > horaAc) {
      lcd.print("mON");
    } else if (arrayS2[1] == 1) {
      lcd.print("hON");
    } else {
      lcd.print("OFF");
    }
    lcd.setCursor(4, 2);
    if (arrayAM[2] > horaAc) {
      lcd.print("mON");
    } else if (arrayS2[2] == 1) {
      lcd.print("hON");
    } else {
      lcd.print("OFF");
    }
    lcd.setCursor(9, 2);
    if (arrayAM[3] > horaAc) {
      lcd.print("mON");
    } else if (arrayS2[3] == 1) {
      lcd.print("hON");
    } else {
      lcd.print("OFF");
    }
    lcd.setCursor(14, 2);
    if (arrayAM[4] > horaAc) {
      lcd.print("mON");
    } else if (arrayS2[4] == 1) {
      lcd.print("hON");
    } else {
      lcd.print("OFF");
    }
    lcd.setCursor(0, 3);
    if (arrayAM[5] > horaAc) {
      lcd.print("mON");
    } else if (arrayS2[5] == 1) {
      lcd.print("hON");
    } else {
      lcd.print("OFF");
    }
    lcd.setCursor(4, 3);
    if (arrayAM[6] > horaAc) {
      lcd.print("mON");
    } else if (arrayS2[6] == 1) {
      lcd.print("hON");
    } else {
      lcd.print("OFF");
    }
    lcd.setCursor(9, 3);
    if (arrayAM[7] > horaAc) {
      lcd.print("mON");
    } else if (arrayS2[7] == 1) {
      lcd.print("hON");
    } else {
      lcd.print("OFF");
    }
  } else {
    lcd.setCursor(0, 2);
    lcd.print("S1 ");
    lcd.setCursor(4, 2);
    lcd.print("S2 ");
    lcd.setCursor(9, 2);
    lcd.print("S3 ");
    lcd.setCursor(14, 2);
    lcd.print("S4 ");
    lcd.setCursor(0, 3);
    lcd.print("S5 ");
    lcd.setCursor(4, 3);
    lcd.print("S6 ");
    lcd.setCursor(9, 3);
    lcd.print("S7 ");
  }

  xKey();
  switch (key) {
    case 'D':
      mNivel1 = mNivel1 + 1;
      neW = 0;
      break;
    case 'C':
      mNivel1 = 7;
      break;
    case '*':
      IO = 0;
      break;
    case '#':
      IO = 1;
      break;
    case 'A':
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("C-D navega menu");
      lcd.setCursor(0, 1);
      lcd.print("A ayuda");
      lcd.setCursor(0, 2);
      lcd.print("# Activa programador");
      lcd.setCursor(0, 3);
      lcd.print("* Apaga riegos");
      lcd.setCursor(19, 3);
      lcd.print("5");
      delay(1000);
      lcd.setCursor(19, 3);
      lcd.print("4");
      delay(1000);
      lcd.setCursor(19, 3);
      lcd.print("3");
      delay(1000);
      lcd.setCursor(19, 3);
      lcd.print("2");
      delay(1000);
      lcd.setCursor(19, 3);
      lcd.print("1");
      break;
    default:
      break;
  }
  //    delay(200);
}
//---------------------------------------------------------
// ARRANQUE MANUAL                                      111
//---------------------------------------------------------
void manS() {
  if (!cCount || !neW) {
    lcd.clear();
    neW = 1;
  }
  lcd.noBlink();
  lcd.setCursor(0, 0);
  lcd.print("C<ARRANQUE MANUAL>D>");
  lcd.setCursor(0, 1);
  lcd.print("S");
  lcd.setCursor(0, 2);
  lcd.print("T");
  lcd.setCursor(0, 3);
  lcd.print("s");
  lcd.setCursor(3, 1);
  for (int i = 1; i < 8; i++) {
    arrayTAM[i] = progCon[i][3];
  }//tam tr
  lcd.print("1");
  lcd.setCursor(3, 2);
  lcd.print(arrayTAM[1]);
  lcd.setCursor(3, 3);
  if (arrayAM[1] > horaAc) {
    lcd.print("ON");
  }
  if (arrayAM[1] <= horaAc) {
    lcd.print("off");
  }
  lcd.setCursor(7, 1);
  lcd.print("2");
  lcd.setCursor(7, 2);
  lcd.print(arrayTAM[2]);
  lcd.setCursor(7, 3);
  if (arrayAM[2] > horaAc) {
    lcd.print("ON");
  }
  if (arrayAM[2] <= horaAc) {
    lcd.print("off");
  }
  lcd.setCursor(11, 1);
  lcd.print("3");
  lcd.setCursor(11, 2);
  lcd.print(arrayTAM[3]);//
  lcd.setCursor(11, 3);
  if (arrayAM[2] > horaAc) {
    lcd.print("ON");
  }
  if (arrayAM[3] <= horaAc) {
    lcd.print("off");
  }
  lcd.setCursor(15, 1);
  lcd.print("4");
  lcd.setCursor(15, 2);
  lcd.print(arrayTAM[4]);//
  lcd.setCursor(15, 3);
  if (arrayAM[4] > horaAc) {
    lcd.print("ON");
  }
  if (arrayAM[4] <= horaAc) {
    lcd.print("off");
  }
  xKey();
  switch (key) {
    case 'B':
    case '5':
    case '6':
    case '7':
      mNivel1 = mNivel1 + 1;
      neW = 0;
      break;
    case 'D':
      mNivel1 = mNivel1 + 2;
      neW = 0;
      break;
    case 'C':
      mNivel1 = mNivel1 - 1;
      neW = 0;
      break;
    case '1': //on-of S1
      if (arrayAM[1] >= horaAc) {
        arrayAM[1] = (horaAc - 2);
      }
      else if (arrayAM[1] < horaAc) {
        arrayAM[1] = horaAc + arrayTAM[1];
      }
      break;
    case '2': //on-of S2
      if (arrayAM[2] >= horaAc) {
        arrayAM[2] = (horaAc - 2);
      }
      else if (arrayAM[2] < horaAc) {
        arrayAM[2] = horaAc + arrayTAM[2];
      }
      break;
    case '3': //on-of S3
      if (arrayAM[3] >= horaAc) {
        arrayAM[3] = (horaAc - 2);
      }
      else if (arrayAM[3] < horaAc) {
        arrayAM[3] = horaAc + arrayTAM[3];
      }
      break;
    case '4': //on-of S4
      if (arrayAM[4] >= horaAc) {
        arrayAM[4] = (horaAc - 2);
      }
      else if (arrayAM[4] < horaAc) {
        arrayAM[4] = horaAc + arrayTAM[4];
      }
      break;
    case 'A':
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Num ON - OFF ");
      lcd.setCursor(0, 1);
      lcd.print("#edit -B (T) A +");
      lcd.setCursor(0, 2);
      lcd.print("izq C - D drcha ");
      lcd.setCursor(0, 3);
      lcd.print("* OFF  ON #(0=5min)");
      delay(5000);
      break;
    case '#':
      mNivel2 = 1;
      exiT = 0;
      while (!exiT) {
        lcd.blink();
        xKey();
        switch (mNivel2) {
          case 1:
            lcd.setCursor(3, 3);
            if (key == 'D') {
              mNivel2 = 2;
            }
            if (key == 'C') {
              mNivel2 = 4;
            }
            if (key == 'A') {
              arrayTAM[1] = arrayTAM[1] + 1;
              lcd.setCursor(3, 2);
              lcd.print(arrayTAM[1]);
            }
            if ((key == 'B') && (arrayTAM[1] > 0)) {
              arrayTAM[1] = arrayTAM[1] - 1;
              lcd.setCursor(3, 2);
              lcd.print(arrayTAM[1]);
            }
            if (key == '0' || key == '*') {
              arrayAM[1] = horaAc;
              exiT = 1;
            }
            if (key == '#') {
              if (arrayTAM[1] == 0) {
                arrayTAM[1] = 5;
              }
              arrayAM[1] = horaAc + arrayTAM[1];
              exiT = 1;
            }
            break;
          case 2:
            lcd.setCursor(7, 3);
            if (key == 'C') {
              mNivel2 = 1;
            }
            if (key == 'D') {
              mNivel2 = 3;
            }
            if (key == 'A') {
              arrayTAM[2] = arrayTAM[2] + 1;
              lcd.setCursor(7, 2);
              lcd.print(arrayTAM[2]);
            }
            if ((key == 'B') && (arrayTAM[2] > 0)) {
              arrayTAM[2] = arrayTAM[2] - 1;
              lcd.setCursor(7, 2);
              lcd.print(arrayTAM[2]);
            }
            if (key == '0' || key == '*') {
              arrayAM[2] = horaAc;
              exiT = 1;
            }
            if (key == '#') {
              if (arrayTAM[2] == 0) {
                arrayTAM[2] = 5;
              }
              arrayAM[2] = horaAc + arrayTAM[2];
              exiT = 1;
            }
            break;
          case 3:
            lcd.setCursor(11, 3);
            if (key == 'C') {
              mNivel2 = 2;
            }
            if (key == 'D') {
              mNivel2 = 4;
            }
            if (key == 'A') {
              arrayTAM[3] = arrayTAM[3] + 1;
              lcd.setCursor(11, 2);
              lcd.print(arrayTAM[3]);
            }
            if ((key == 'B') && (arrayTAM[3] > 0)) {
              arrayTAM[3] = arrayTAM[3] - 1;
              lcd.setCursor(11, 2);
              lcd.print(arrayTAM[3]);
            }
            if (key == '0' || key == '*') {
              arrayAM[3] = horaAc;
              exiT = 1;
            }
            if (key == '#') {
              if (arrayTAM[3] == 0) {
                arrayTAM[3] = 5;
              }
              arrayAM[3] = horaAc + arrayTAM[3];
              exiT = 1;
            }
            break;
          case 4:
            lcd.setCursor(15, 3);
            if (key == 'C') {
              mNivel2 = 3;
            }
            if (key == 'D') {
              mNivel2 = 1;
            }
            if (key == 'A') {
              arrayTAM[4] = arrayTAM[4] + 1;
              lcd.setCursor(15, 2);
              lcd.print(arrayTAM[4]);
            }
            if ((key == 'B') && (arrayTAM[4] > 0)) {
              arrayTAM[4] = arrayTAM[4] - 1;
              lcd.setCursor(15, 2);
              lcd.print(arrayTAM[4]);
            }
            if (key == '0' || key == '*') {
              arrayAM[4] = horaAc;
              exiT = 1;
            }
            if (key == '#') {
              if (arrayTAM[4] == 0) {
                arrayTAM[4] = 5;
              }
              arrayAM[4] = horaAc + arrayTAM[4];
              exiT = 1;
            }
            break;
          default:
            break;
        }//switch mNivel2
      }//While
      break;
  }//switch case
}
void manS2() { ////////////////////////////////////////////////ARRANQUE MANUAL 222222222222222
  if (!cCount || !neW) {
    lcd.clear();
    neW = 1;
  }
  lcd.noBlink();
  lcd.setCursor(0, 0);
  lcd.print("C<ARRANQUE MANUAL>D>");
  lcd.setCursor(0, 1);
  lcd.print("S");
  lcd.setCursor(0, 2);
  lcd.print("T");
  lcd.setCursor(0, 3);
  lcd.print("s");
  lcd.setCursor(3, 1);
  for (int i = 1; i < 8; i++) {
    arrayTAM[i] = progCon[i][3];
  }//tam tr
  lcd.print("5");
  lcd.setCursor(3, 2);
  lcd.print(arrayTAM[5]);
  lcd.setCursor(3, 3);
  if (arrayAM[5] > horaAc) {
    lcd.print("ON");
  }
  if (arrayAM[5] <= horaAc) {
    lcd.print("off");
  }
  lcd.setCursor(7, 1);
  lcd.print("6");
  lcd.setCursor(7, 2);
  lcd.print(arrayTAM[6]);
  lcd.setCursor(7, 3);
  if (arrayAM[6] > horaAc) {
    lcd.print("ON");
  }
  if (arrayAM[6] <= horaAc) {
    lcd.print("off");
  }
  lcd.setCursor(11, 1);
  lcd.print("7");
  lcd.setCursor(11, 2);
  lcd.print(arrayTAM[7]);//
  lcd.setCursor(11, 3);
  if (arrayAM[7] > horaAc) {
    lcd.print("ON");
  }
  if (arrayAM[7] <= horaAc) {
    lcd.print("off");
  }
  xKey();
  switch (key) {
    case 'D':
      mNivel1 = mNivel1 + 1;
      break;
    case 'A':
    case 'B':
    case '1':
    case '2':
    case '3':
    case '4':
      mNivel1 = mNivel1 - 1;
      neW = 0;
      break;
    case 'C':
      mNivel1 = mNivel1 - 2;
      neW = 0;
      break;
    case '5': //on-of S5
      if (arrayAM[5] >= horaAc) {
        arrayAM[5] = (horaAc - 2);
      }
      else if (arrayAM[5] < horaAc) {
        arrayAM[5] = horaAc + arrayTAM[5];
      }
      break;
    case '6': //on-of S6
      if (arrayAM[6] >= horaAc) {
        arrayAM[6] = (horaAc - 2);
      }
      else if (arrayAM[6] < horaAc) {
        arrayAM[6] = horaAc + arrayTAM[6];
      }
      break;
    case '7': //on-of S7
      if (arrayAM[7] >= horaAc) {
        arrayAM[7] = (horaAc - 2);
      }
      else if (arrayAM[7] < horaAc) {
        arrayAM[7] = horaAc + arrayTAM[7];
      }
      break;
    case '#':
      mNivel2 = 1;
      while (!exiT) {
        lcd.blink();
        xKey();
        switch (mNivel2) {
          case 1:
            lcd.setCursor(3, 3);
            if (key == 'D') {
              mNivel2 = 2;
            }
            if (key == 'C') {
              mNivel2 = 3;
            }
            if (key == 'A') {
              arrayTAM[5] = arrayTAM[5] + 1;
              lcd.setCursor(3, 2);
              lcd.print(arrayTAM[5]);
            }
            if ((key == 'B') && (arrayTAM[5] > 0)) {
              arrayTAM[5] = arrayTAM[5] - 1;
              lcd.setCursor(3, 2);
              lcd.print(arrayTAM[5]);
            }
            if (key == '0' || key == '*') {
              arrayAM[5] = horaAc;
              exiT = 1;
            }
            if (key == '#') {
              if (arrayTAM[5] == 0) {
                arrayTAM[5] = 5;
              }
              arrayAM[5] = horaAc + arrayTAM[5];
              exiT = 1;
            }
            break;
          case 2:
            lcd.setCursor(7, 3);
            if (key == 'C') {
              mNivel2 = 1;
            }
            if (key == 'D') {
              mNivel2 = 3;
            }
            if (key == 'A') {
              arrayTAM[6] = arrayTAM[6] + 1;
              lcd.setCursor(7, 2);
              lcd.print(arrayTAM[6]);
            }
            if ((key == 'B') && (arrayTAM[6] > 0)) {
              arrayTAM[6] = arrayTAM[6] - 1;
              lcd.setCursor(7, 2);
              lcd.print(arrayTAM[6]);
            }
            if (key == '0' || key == '*') {
              arrayAM[6] = horaAc;
              exiT = 1;
            }
            if (key == '#') {
              if (arrayTAM[6] == 0) {
                arrayTAM[6] = 5;
              }
              arrayAM[6] = horaAc + arrayTAM[6];
              exiT = 1;
            }
            break;
          case 3:
            lcd.setCursor(11, 3);
            if (key == 'C') {
              mNivel2 = 2;
            }
            if (key == 'D') {
              mNivel2 = 1;
            }
            if (key == 'A') {
              arrayTAM[7] = arrayTAM[7] + 1;
              lcd.setCursor(15, 2);
              lcd.print(arrayTAM[7]);
            }
            if ((key == 'B') && (arrayTAM[7] > 0)) {
              arrayTAM[7] = arrayTAM[7] - 1;
              lcd.setCursor(15, 2);
              lcd.print(arrayTAM[7]);
            }
            if (key == '0' || key == '*') {
              arrayAM[7] = horaAc;
              exiT = 1;
            }
            if (key == '#') {
              if (arrayTAM[7] == 0) {
                arrayTAM[7] = 5;
              }
              arrayAM[7] = horaAc + arrayTAM[7];
              exiT = 1;
            }
            break;
          default:
            break;
        }
      }//While
      break;
  }//switch case
}
//---------------------------------------------------------
// SUSPENSION EXTERIOR                                  333
//---------------------------------------------------------
void Delay() {
  lcd.noBlink();
  lcd.setCursor(0, 0);
  lcd.print("<C<< SUSPENSION >>D>");
  lcd.setCursor(0, 1);
  lcd.print("Riego exterior");
  if (del == 0) {
    lcd.setCursor(0, 2);
    lcd.print("     activado");
    lcd.setCursor(0, 3);
    lcd.print("+A,#   -B   *=0");
  } else if (del == 24) {
    lcd.setCursor(0, 2);
    lcd.print("suspendido 1 dia");
    lcd.setCursor(0, 3);
    lcd.print("+A,#   -B   *=0");
  } else if (del == 48) {
    lcd.setCursor(0, 2);
    lcd.print("suspendido 2 dias");
    lcd.setCursor(0, 3);
    lcd.print("+A,#   -B   *=0");
  } else if (del == 72) {
    lcd.setCursor(0, 2);
    lcd.print("suspendido 3 dias");
    lcd.setCursor(0, 3);
    lcd.print("+A,#   -B   *=0");
  } else if (del > 0 && del < 72) { //err 254
    lcd.setCursor(0, 2);
    lcd.print("suspendido ");
    lcd.print(del);
    lcd.print(" horas");
    lcd.setCursor(0, 3);
    lcd.print("+A,#   -B   *=0");
  } else if (del > 72) {
    lcd.setCursor(0, 2);
    lcd.print("    SUSPENDIDO");
    lcd.setCursor(0, 3);
    lcd.print(" INDEFINIDAMENTE *");
  }
  xKey();
  switch (key) {
    case 'D':
      mNivel1 = mNivel1 + 1;
      break;
    case 'C':
      mNivel1 = mNivel1 - 2;
      break;
    case'#':
    case 'A':
      if (del < 84)del = del + 12;
      break;
    case'B':
      if (del <= 12 && del > 0) {
        del = del - 4;
      } else if (del <= 4 && del > 0) {
        del = del - 1;
      } else if (del > 12) {
        del = del - 12;
      }
      break;
    case '*':
      del = 0;
      break;
    default:
      break;
  }//switch key
}
//---------------------------------------------------------
// SET PORCENTAJE                                             444
//---------------------------------------------------------
void setPorc() {
  lcd.noBlink();
  xKey();
  lcd.setCursor(0, 0);
  lcd.print("C<<SET PORCENTAJE>>D");
  lcd.setCursor(0, 1);
  lcd.print(" valido 10% a 250%");
  lcd.setCursor(1, 3);
  lcd.print("-B (");
  lcd.print(porc);
  lcd.print("% de T) A+");
  switch (key) {
    case 'D':
      mNivel1 = mNivel1 + 1;
      neW = 1;
      break;
    case 'C':
      mNivel1 = mNivel1 - 1;
      break;
    case '#':
    case 'A':
      if (porc < 250) {
        porc = porc + 10;
        syncProg();
      }
      break;
    case 'B':
      if (porc > 10) {
        porc = porc - 10;
        syncProg();
      }
      break;
    case '*':
      porc = 100;
      break;
  }
}
//---------------------------------------------------------
// SET HORA                                            666
//---------------------------------------------------------
void setHora () {
  int f;
  char string[] = "0 :  ";
  if (!cCount || !neW) {
    lcd.clear();
    neW = 1;
  }
  lcd.setCursor(0, 0);
  lcd.print("<C<<< SET HORA >>>D>");
  lcd.setCursor(0, 1);
  lcd.print("Actual" );
  if (now.hour() > 9) lcd.setCursor(8, 1);
  if (now.hour() < 10) lcd.setCursor(9, 1);
  lcd.print(now.hour(), DEC);
  printDigits(now.minute());
  lcd.setCursor(0, 3);
  lcd.print("num *cancel #save");
  lcd.setCursor(0, 2);
  lcd.print("new     ");
  lcd.print (iH);
  lcd.setCursor(8 + f, 2);
  lcd.blink();
  xKey();
  switch (key) {
    case 'D':
      mNivel1 = mNivel1 + 1;
      neW = 0;
      break;
    case 'C':
      mNivel1 = mNivel1 - 1;
      break;
    case '0':
    case '1':
    case '2':
      lastKey = key;
      introH(2);///////no vale asignar valores dentro de la funcion
      ihh = (((buffer[0] - '0') * 10) + (buffer[1] - '0'));
      imm = (((buffer[2] - '0') * 10) + (buffer[3] - '0'));
      if (0 > ihh > 23) {
        ihh = 0;
      }
      if (0 >= ihh > 59) {
        imm = 0;
      }
      if (ihh != 0 && imm != 0) {
        gHora();
      }
      clearBuffer();
      break;
  }//switch key
}
void gHora() {
  DateTime dt(2015, 1, 1, ihh, imm, 0, 0);
  rtc.setDateTime(dt) ;//year, month, date, hour, min, sec and week-day(starts from 0(sunday) and goes to 6)
}
//---------------------------------------------------------
// SET PROGRAMA                                        777
//---------------------------------------------------------
void setProg () {
  if (!cCount || !neW) {
    lcd.clear();
    neW = 1;
  }
  lcd.noBlink();
  lcd.setCursor(0, 0);
  lcd.print("<C<<< PROGRAMA >>>D>");
  lcd.setCursor(0, 1);
  lcd.print("S");
  lcd.print(s);
  lcd.setCursor(3, 1);
  if (progRec[s][3] == 0) {
    lcd.print("OFF");
  }
  if (progRec[s][3] != 0) {
    lcd.print("ON");
  }
  lcd.setCursor(7, 1);
  lcd.print("TR ");
  lcd.print(progRec[s][3]);
  lcd.setCursor(13, 1);
  lcd.print("Inv?");
  lcd.print(progRec[s][2]);

  lcd.setCursor(0, 2);
  lcd.print(progRec[s][4]);
  printDigits(progRec[s][5]);
  lcd.setCursor(6, 2);
  lcd.print(progRec[s][6]);
  printDigits(progRec[s][7]);
  lcd.setCursor(12, 2);
  lcd.print(progRec[s][8]);
  printDigits(progRec[s][9]);

  lcd.setCursor(0, 3);
  lcd.print(progRec[s][10]);
  printDigits(progRec[s][11]);
  lcd.setCursor(6, 3);
  lcd.print(progRec[s][12]);
  printDigits(progRec[s][13]);
  lcd.setCursor(12, 3);
  lcd.print(progRec[s][14]);
  printDigits(progRec[s][15]);

  xKey();
  switch (key) {
    case 'D':
      mNivel1 = mNivel1 + 1;
      break;
    case 'C':
      mNivel1 = mNivel1 - 1;
      neW = 0;
      break;
    case 'A':
      if (s == 1) {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("T en  minutos <99");
        lcd.setCursor(0, 1);
        lcd.print("Num A B sector");
        lcd.setCursor(0, 2);
        lcd.print(" # editar");
        lcd.setCursor(0, 3);
        lcd.print(" * # salir");
        delay(5000);
      }
      if (s > 1) {
        s = s - 1;
      }
      break;
    case 'B':
      if (s < 7) {
        s = s + 1;
      }
      break;
    case '1':
      s = 1;
      break;
    case '2':
      s = 2;
      break;
    case '3':
      s = 3;
      break;
    case '4':
      s = 4;
      break;
    case '5':
      s = 5;
      break;
    case '6':
      s = 6;
      break;
    case '7':
      s = 7;
      break;
    case '#':
      mNivel2 = 1;
      while (key != '*') {
        xKey();
        switch (mNivel2) {
          case 1:                   //set Tiempo de riego//////hacer funcion settr
            lcd.setCursor(10, 1);
            lcd.blink();
            if (key == 'D') {
              mNivel2 = 2;
            }
            if (key == 'B') {
              mNivel2 = 4;
            }
            if (key == '#') {
              return;
            }
            if (validKeys0to9(key)) {
              storeKey(key);
              progRec[s][3] = buffer[0] - '0';
              lcd.print(buffer[0]);
              key = customKeypad.waitForKey();
              if (validKeys0to9(key)) {
                storeKey(key);
                progRec[s][3] = int(((buffer[0] - '0') * 10) + (buffer[1] - '0'));
                lcd.setCursor(10, 1);
                lcd.print(progRec[s][3]);
              }
              if (key == 'D') {
                lcd.print(" ");
              }
              if (key == '#') {
                lcd.print(" ");
                return;
              }
              clearBuffer();
              mNivel2 = 2;
            }
            if (key == 'D') {
              mNivel2 = 2;
            }
            break;
          case 2:          //set inernadero
            lcd.setCursor(17, 1);
            if (key == 'C') {
              mNivel2 = 1;
            }
            if (key == 'B') {
              mNivel2 = 5;
            }
            if (validKeys0to1(key)) {
              progRec[s][2] = key - '0';
              lcd.print(key);
              mNivel2 = 3;
            }
            if (key == 'D') {
              mNivel2 = 3;
            }
            if (key == '#') {
              return;
            }
            break;
          case 3:                           //set H1
            lcd.setCursor(0, 2);
            if (key == 'A') {
              mNivel2 = 1;
            }
            if (key == 'B') {
              mNivel2 = 6;
            }
            if (key == 'C') {
              mNivel2 = 2;
            }
            if (key == 'D') {
              mNivel2 = 4;
            }
            if (key == '#') {
              return;
            }
            if (validKeys0to2(key)) {
              lastKey = key;
              introH(0);///////no vale asignar valores dentro de la funcion
              progRec[s][4] = (((buffer[0] - '0') * 10) + (buffer[1] - '0'));
              progRec[s][5] = (((buffer[2] - '0') * 10) + (buffer[3] - '0'));
              if (progRec[s][4] > 23) {
                progRec[s][4] = 0;
              }
              if (progRec[s][5] > 59) {
                progRec[s][5] = 0;
              }
              clearBuffer();
            }
            break;
          case 4:                           //set H2
            lcd.setCursor(6, 2);
            if (key == 'A') {
              mNivel2 = 1;
            }
            if (key == 'B') {
              mNivel2 = 7;
            }
            if (key == 'C') {
              mNivel2 = 3;
            }
            if (key == 'D') {
              mNivel2 = 5;
            }
            if (key == '#') {
              return;
            }
            if (validKeys0to2(key)) {
              lastKey = key;
              introH(1);
              progRec[s][6] = (((buffer[0] - '0') * 10) + (buffer[1] - '0'));
              progRec[s][7] = (((buffer[2] - '0') * 10) + (buffer[3] - '0'));
              if (progRec[s][6] > 23) {
                progRec[s][6] = 0;
              }
              if (progRec[s][7] > 59) {
                progRec[s][7] = 0;
              }
              clearBuffer();
            }
            break;
          case 5: //set H3
            lcd.setCursor(12, 2);
            if (key == 'A') {
              mNivel2 = 2;
            }
            if (key == 'B') {
              mNivel2 = 8;
            }
            if (key == 'C') {
              mNivel2 = 4;
            }
            if (key == 'D') {
              mNivel2 = 6;
            }
            if (key == '#') {
              return;
            }
            if (validKeys0to2(key)) {
              lastKey = key;
              introH(2);
              progRec[s][8] = (((buffer[0] - '0') * 10) + (buffer[1] - '0'));
              progRec[s][9] = (((buffer[2] - '0') * 10) + (buffer[3] - '0'));
              if (progRec[s][8] > 23) {
                progRec[s][8] = 0;
              }
              if (progRec[s][9] > 59) {
                progRec[s][9] = 0;
              }
              clearBuffer();
            }
            break;
          case 6: //set H4
            lcd.setCursor(0, 3);
            if (key == 'A') {
              mNivel2 = 3;
            }
            if (key == 'C') {
              mNivel2 = 5;
            }
            if (key == 'D') {
              mNivel2 = 7;
            }
            if (key == '#') {
              return;
            }
            if (validKeys0to2(key)) {
              lastKey = key;
              introH(3);
              progRec[s][10] = (((buffer[0] - '0') * 10) + (buffer[1] - '0'));
              progRec[s][11] = (((buffer[2] - '0') * 10) + (buffer[3] - '0'));
              if (progRec[s][10] > 23) {
                progRec[s][10] = 0;
              }
              if (progRec[s][11] > 59) {
                progRec[s][11] = 0;
              }
              clearBuffer();
            }
            break;
          case 7: //set H5
            lcd.setCursor(6, 3);
            if (key == 'A') {
              mNivel2 = 4;
            }
            if (key == 'C') {
              mNivel2 = 6;
            }
            if (key == 'D') {
              mNivel2 = 8;
            }
            if (key == '#') {
              return;
            }
            if (validKeys0to2(key)) {
              lastKey = key;
              introH(4);
              progRec[s][12] = (((buffer[0] - '0') * 10) + (buffer[1] - '0'));
              progRec[s][13] = (((buffer[2] - '0') * 10) + (buffer[3] - '0'));
              if (progRec[s][12] > 23) {
                progRec[s][12] = 0;
              }
              if (progRec[s][13] > 59) {
                progRec[s][13] = 0;
              }
              clearBuffer();
            }
            break;
          case 8: //set H6
            lcd.setCursor(12, 3);
            if (key == 'A') {
              mNivel2 = 5;
            }
            if (key == 'C') {
              mNivel2 = 7;
            }
            if (key == 'D') {
              mNivel2 = 9;
            }
            if (key == '#') {
              return;
            }
            if (validKeys0to2(key)) {
              lastKey = key;
              introH(2);
              progRec[s][14] = (((buffer[0] - '0') * 10) + (buffer[1] - '0'));
              progRec[s][15] = (((buffer[2] - '0') * 10) + (buffer[3] - '0'));
              if (progRec[s][14] > 23) {
                progRec[s][14] = 0;
              }
              if (progRec[s][15] > 59) {
                progRec[s][15] = 0;
              }
              clearBuffer();
              mNivel2 = 9;
            }
            break;
          case 9:
            return;
            break;
          default:
            break;
        }//switch(SPState)
      }//while (key!='*')
  }//switch
}
void introH(int nh) {                                     //intro hora
  int state = 1;
  lcd.print (lastKey);
  storeKey(lastKey);
  exiT = 0;
  while (!exiT) {
    xKey ();
    switch (state) {
      case 1://1ºdigito ya viene
        if (lastKey == 2 && validKeys0to3(key)) {
          lcd.print(key);
          storeKey(key);
          state = 2;
        } else if (lastKey != 2 && validKeys0to9(key)) {
          lcd.print(key);
          storeKey(key);
          state = 2;
        } else if (key == 'D' || key == '#') {
          state = 2;
        } else if (key == '*') {
          clearBuffer();
          exiT = 1;
        }
        break;
      case 2:
        lcd.print(":");
        state = 3;
        break;
      case 3:   //minuto1º
        if (validKeys0to5(key)) {
          storeKey(key);
          lcd.print(key);
          state = 4;
        } else if (key == '*') {
          clearBuffer();
          exiT = 1;
        }
        break;
      case 4://min2
        if (validKeys0to9(key)) {
          lcd.print(key);
          storeKey(key);
          state = 5;//acepta o descarta
        } else if (key == 'C') {
          state = 5;
        } else if (key == '*') {
          clearBuffer();
          exiT = 1;
        }
        break;
      case 5://no vale asignar los valores aqui
        //progRec[ss][nh+4]= (((buffer[0]-'0')*10)+(buffer[1]-'0'));
        //progRec[ss][nh+5]= (((buffer[2]-'0')*10)+(buffer[3]-'0'));
        //clearBuffer();
        mNivel2 = nh + 4;
        return;//sale a
        break;
      default:
        break;
    }//switch
  }//while
  clearBuffer();
}
void clearBuffer(void) {//podria vaciarse con '0' y no '\0'
  buffer[0] = '0';     //evitaria valor negativo al restar '0'
  buffer[1] = '0';
  buffer[2] = '0';
  buffer[3] = '0';
  index = 0;
}// Store key in buffer
void storeKey(char key) {
  buffer[index] = key;
  index++;
}
//---------------------------------------------------------
// BORRA/GUARDA PROGAMA EN EEPROM                       777
//---------------------------------------------------------
void borraP () {
  int a;
  int b;
  lcd.noBlink();
  lcd.setCursor(0, 0);
  lcd.print("<C< BORRA/SALVA >>D>");
  lcd.setCursor(7, 1);
  lcd.print("EEPROM");
  lcd.setCursor(0, 2);
  lcd.print("* Borra  Guarda #");
  lcd.setCursor(3, 3);
  lcd.print(EPROMcount);
  lcd.print(" usos");

  xKey();
  switch (key) {
    case 'D':
      mNivel1 = 0;
      neW = 0;
      break;
    case 'C':
      mNivel1 = mNivel1 - 1;
      neW = 0;
      break;
    case 'A':
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("guarda programa");
      lcd.setCursor(0, 1);
      lcd.print("en memoria interna");
      lcd.setCursor(0, 2);
      lcd.print("estara disponible");
      lcd.setCursor(0, 3);
      lcd.print("despues de reiniciar");
      delay(6000);
      break;
    case 'B':
      break;
    case '*':
      for (a = 1; a < 8; a++) { //dejo s0
        for (b = 1; b < 16; b++) { //dejo index
          progRec[a][b] = 0;
        }
      }
      eepromWrite();
      syncProg();
      lcd.setCursor(0, 2);
      lcd.print("   borrando.....   ");
      delay(3000);
      break;
    case '#':
      eepromWrite();
      syncProg();
      lcd.setCursor(0, 3);
      lcd.print("   Guardando.....   ");
      delay(3000);
      break;
  }
  delay(100);
}
void syncProg() { //en minuto del dia max 1440 =24*60
  for (int i = 1; i < 8; i++) {
    progCon[i][2] = progRec[i][2]; //inv
    progCon[i][3] = progRec[i][3]; //Tr
    progCon[i][4] = ((progRec[i][4] * 60) + (progRec[i][5])); //h1-inicial " en minutos"
    progCon[i][5] = int((progCon[i][4]) + ((progRec[i][3]) * (porc / 100))); //h1 final
    progCon[i][6] = ((progRec[i][6] * 60) + progRec[i][7]); //h1-inicial
    progCon[i][7] = int((progCon[i][6]) + ((progRec[i][3]) * (porc / 100))); //h1 final
    progCon[i][8] = ((progRec[i][8] * 60) + progRec[i][9]); //h1-inicial
    progCon[i][9] = int((progCon[i][8]) + ((progRec[i][3]) * (porc / 100))); //h1 final
    progCon[i][10] = ((progRec[i][10] * 60) + progRec[i][11]); //h1-inicial
    progCon[i][11] = int((progCon[i][10]) + ((progRec[i][3]) * (porc / 100))); //h1 final
    progCon[i][12] = ((progRec[i][12] * 60) + progRec[i][13]); //h1-inicial
    progCon[i][13] = int((progCon[i][12]) + ((progRec[i][3]) * (porc / 100))); //h1 final
    progCon[i][14] = ((progRec[i][14] * 60) + progRec[i][15]); //h1-inicial
    progCon[i][15] = int ((progCon[i][14]) + ((progRec[i][3]) * (porc / 100))); //h1 final
  }

}
void eepromWrite() {
  int address = 0;
  for (int i = 1; i < 8; i++) {
    for (int j = 3; j < 16; j++) {
      EEPROM.writeInt(address, progRec[i][j]);
      address += 2;
    }
  }
  EEPROM.writeInt(298, (EPROMcount + 1));
  EPROMcount = EPROMcount + 1;
}
void eepromRead() {
  int address = 0;
  for (int i = 1; i < 8; i++) {
    for (int j = 3; j < 16; j++) {
      progRec[i][j] = EEPROM.readInt(address);
      address += 2;
    }
  }
  EPROMcount = (EEPROM.readInt(298) + 1);
}
/////////////////////////////////////////////////////
//necesario para contador backlight última pulsación
void xKey() {
  key = customKeypad.getKey();
  if (key != resetKey) {
    timer = 0;
    if (mNivel1 == 7 || mNivel1 == 4 || mNivel1 == 3) {
      lcd.clear();
    }
  }
  resetKey = key;
}
//////////////////////////////////imprime minutos :00
void printDigits(byte digits) {
  lcd.print(":");
  if (digits < 10) {
    lcd.print('0');
    lcd.print(digits, DEC);
  }
  else {
    lcd.print(digits, DEC);
  }
}
///////////////////////////////validaciones de teclas
// Validate keys: 0-9
// return true if valid, else false
int validKeys0to9(int key) {
  int valid = 0;
  switch (key) {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      valid = 1;
      break;
  }
  return valid;
}
// Validate keys: 0-5
int validKeys0to5(int key) {
  int valid = 0;
  switch (key) {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
      valid = 1;
      break;
  }
  return valid;
}
// Validate keys: 0-4
int validKeys0to3(int key) {
  int valid = 0;
  switch (key) {
    case '0':
    case '1':
    case '2':
    case '3':
      valid = 1;
      break;
  }
  return valid;
}
// Validate keys: 0-2
// return true if valid, else false
int validKeys0to2(int key) {
  int valid = 0;
  switch (key) {
    case '0':
    case '1':
    case '2':
      valid = 1;
      break;
  }
  return valid;
}
// Validate keys: 0-1
// return true if valid, else false
int validKeys0to1(int key) {
  int valid = 0;
  switch (key) {
    case '0':
    case '1':
      valid = 1;
      break;
  }
  return valid;
}

sheck modificado:

//---------------------------------------------------
// 2.     Include framework code and libraries
//---------------------------------------------------

#include <Wire.h>                 //I2C DS1307 RTC
#include <LiquidCrystal_I2C.h>    //lcd IIC
#include <Keypad.h>
#include <SPI.h>
#include <Sodaq_DS3231.h>//rtc ds3231
#include <EEPROMex.h>
#include <EEPROMVar.h>

//*****************************BIG RELOJ***************************************************************************************
#include <avr/pgmspace.h>            // for memory storage in program space
//******************************************************************************************************************************

//----------------------------------------------------
// 5. Pines
//----------------------------------------------------
//pin 18 serial1 rx
//pin 19 serial1 rx
//Pin20 SDA IIC reloj+lcd iic
//Pin21 SCL IIC reloj+lcd iic
#define pinS1   22 //pin para relé sector de riego 1
#define pinS2   24
#define pinS3   26
#define pinS4   28
#define pinS5   30
#define pinS6   32
#define pinS7   34
#define pinPump 36 //pin para relé que activa bomba conectado Normalmente Abierto

//******************************BIG RELOJ**********************************************************************************
#define build 1
#define revision 2
//**************************************************************************************************************************

//--keypad-------------------------------------------
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
//----------------------------------------------------
// 6. Variables
//----------------------------------------------------
//-------------keypad
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
int horaAc;// Hora actual en minutos (0 a 1440)
char key;
char lastKey;
char resetKey;//xKey

char buffer[5];
int index = 0;
int pos = 0;

int progRec [8][16];//index, on/off, Inv?, Tr, h1,m1...h6,m6 eprom
int progCon [8][16];//index, ON/OFF, Inv?, Tr, "h ini 1","h final 1",.... "h ini 6","h final 6"
bool IO = 1;//ON/OFF programador
int mNivel1 = 0; //menu nivel 1
int mNivel2 = 0; //menu nivel 2
bool exiT = 0; //sale modo edicion
bool arrayS[8];//control, bomba
bool arrayS2[8];//control, horario+condicionantes
bool arraySActivo[8];//control, horario
int EPROMcount;
int arrayAM[8] = {0, 0, 0, 0, 0, 0, 0, 0}; //arranque manual"horaAC"
int arrayTAM[8] = {0, 0, 0, 0, 0, 0, 0, 0}; //Tiempo en arranque manual
int pinArray[8] = {0, pinS1, pinS2, pinS3, pinS4, pinS5, pinS6, pinS7};
int del = 0; //riego exterior suspendido x horas
int porc = 100; //porcentaje aplicado al tiempo de riego
int lastHour = 0;
int lastSecond = 0;
int timer = 0;
char iH[ ] = "  :  "; //usado en set hora
int ihh, imm;
int s = 1; //usado en set prog

byte cCount;//contador de ciclos
bool neW;

//*****************************BIG RELOJ****************************************************************************************************************************************************************
const char custom[][8] PROGMEM = {
  {0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0F, 0x1F},      // char 1: bottom right triangle
  {0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F},      // char 2: bottom block
  {0x00, 0x00, 0x00, 0x00, 0x10, 0x1C, 0x1E, 0x1F},      // char 3: bottom left triangle
  {0x1F, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00},      // char 4: top right triangle
  {0x1F, 0x1E, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00},      // char 5: top left triangle
  {0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00},      // char 6: upper block
  {0x1F, 0x1F, 0x1E, 0x1C, 0x18, 0x18, 0x10, 0x10}       // char 7: full top right triangle
  // room for another one!
};

const char bn[][30] PROGMEM = {                             // organized by row
  //         0               1               2               3               4              5               6                7               8               9
  {0x01, 0x02, 0x03, 0x01, 0x02, 0xFE, 0x01, 0x02, 0x03, 0x01, 0x02, 0x03, 0x02, 0xFE, 0x02, 0x02, 0x02, 0x02, 0x01, 0x02, 0x03, 0x02, 0x02, 0x02, 0x01, 0x02, 0x03, 0x01, 0x02, 0x03},
  {0xFF, 0xFE, 0xFF, 0xFE, 0xFF, 0xFE, 0x01, 0x02, 0xFF, 0xFE, 0x02, 0xFF, 0xFF, 0x02, 0xFF, 0xFF, 0x02, 0x02, 0xFF, 0x02, 0x03, 0xFE, 0x01, 0x07, 0xFF, 0x02, 0xFF, 0xFF, 0xFE, 0xFF},
  {0xFF, 0xFE, 0xFF, 0xFE, 0xFF, 0xFE, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFE, 0xFE, 0xFF, 0xFE, 0xFE, 0xFF, 0xFF, 0xFE, 0xFF, 0xFE, 0xFF, 0xFE, 0xFF, 0xFE, 0xFF, 0x04, 0x06, 0xFF},
  {0x04, 0x06, 0x05, 0xFE, 0x06, 0xFE, 0x06, 0x06, 0x06, 0x04, 0x06, 0x05, 0xFE, 0xFE, 0x06, 0x04, 0x06, 0x05, 0x04, 0x06, 0x05, 0xFE, 0x06, 0xFE, 0x04, 0x06, 0x05, 0xFE, 0xFE, 0x06}
};

byte col, row, nb = 0, bc = 0;                            // general
byte bb[8];                                               // byte buffer for reading from PROGMEM
byte hr, mn, se, osec;
//RTC_DS3231 RTC;
//***************************************************************************************************************************************************************************************************

//----------------------------------------------------
// 7. Objetos
//----------------------------------------------------
DateTime now;
LiquidCrystal_I2C lcd(0x27, 20, 4);
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad
//DateTime dt(2011, 11, 10, 15, 18, 0, 5);

// =====================================================================================
// SETUP
// =====================================================================================
void setup() {

  //******************************BIG RELOJ********************************************************************
  randomSeed(analogRead(0));
  // RTC.begin();
  for (nb = 0; nb < 7; nb++ ) {                 // create 8 custom characters
    for (bc = 0; bc < 8; bc++) bb[bc] = pgm_read_byte( &custom[nb][bc] );
    lcd.createChar ( nb + 1, bb );
  }
  //***********************************************************************************************************

  rtc.begin();
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 1);
  lcd.print("V.1");
  lcd.noBacklight();

  pinMode(pinPump, OUTPUT);
  digitalWrite(pinPump, HIGH); //para que los reles chinos comiencen apagados
  digitalWrite(pinS1, HIGH);
  pinMode(pinS1, OUTPUT);
  digitalWrite(pinS2, HIGH);
  pinMode(pinS2, OUTPUT);
  digitalWrite(pinS3, HIGH);
  pinMode(pinS3, OUTPUT);
  digitalWrite(pinS4, HIGH);
  pinMode(pinS4, OUTPUT);
  digitalWrite(pinS5, HIGH);
  pinMode(pinS5, OUTPUT);
  digitalWrite(pinS6, HIGH);
  pinMode(pinS6, OUTPUT);
  digitalWrite(pinS7, HIGH);
  pinMode(pinS7, OUTPUT);
  DateTime now = rtc.now();
  horaAc = now.hour() * 60 + now.minute();
  EEPROM.setMemPool(0, EEPROMSizeMega);
  eepromRead();
  
}

// =====================================================================================
// LOOP
// =====================================================================================

void loop() {

  cCount++;
  if (cCount > 20) {
    cCount = 0;
  }

  now = rtc.now();
  horaAc = now.hour() * 60 + now.minute();
  if (horaAc == 0) { //resetea el array arranque manual a las 00:00
    arrayAM[8] = (0, 0, 0, 0, 0, 0, 0, 0);
  }
  if (now.hour() != lastHour) { //resta una hora a la variable de suspensión
    if ((del > 0) && (del < 73)) {
      del = del - 1;
    }
    lastHour = now.hour();
  }

  syncProg();
  menu();
  
 
  //control sectores
  for (int i = 1; i < 8; i++) {
    sectorActivo(i);
  }
  for (int i = 1; i < 8; i++) {
    //si ON y app o programa o arranque manual
    if (IO && ( arraySActivo[8 - 1] || (arrayS2[i]) || (arrayAM[i] > horaAc))) {
      //0x23 app
      digitalWrite(pinArray[i], LOW);
      arrayS[i] = 1;
    } else {
      digitalWrite(pinArray[i], HIGH);
      arrayS[i] = 0;
    }
  }//for
  //control bomba
  if (arrayS[1] || arrayS[2] || arrayS[3] || arrayS[4] || arrayS[5] || arrayS[6] || arrayS[7]) { //control bomba
    digitalWrite(pinPump, LOW);
    lcd.backlight();
  } else {
    digitalWrite(pinPump, HIGH);
  }
  //control lcd.backlight
  if (now.second() != lastSecond) {
    timer++;
    lastSecond = now.second();
  }
  if (timer > 60 && !(arrayS[1] || arrayS[2] || arrayS[3] || arrayS[4] || arrayS[5] || arrayS[6] || arrayS[7])) {
    lcd.backlight();// lcd.noBacklight();
  } else {
    lcd.backlight();
  }
  if (timer > 90) {
    mNivel1 = 0; //vuelve a pantalla de inicio tras 90s de inactividad
  }
  if (timer > 1000) {
    timer = 91; //32k
  }

}
// =====================================================================================
// Fin de LOOP
// =====================================================================================

//*****************************BIG RELOJ************************************************************************

// ********************************************************************************** //
//                                      SUBROUTINES
// ********************************************************************************** //
void PpBig(){
   // DateTime now = RTC.now();
  DateTime now = rtc.now();
  hr = now.hour() % 12 ;
  mn = now.minute();
  se = now.second();
  if (se != osec) {
    printNum(hr / 10, 0);
    printNum(hr % 10, 3);
    printColon(6);
    printNum(mn / 10, 7);
    printNum(mn % 10, 10);
    printColon(13);
    printNum(se / 10, 14);
    printNum(se % 10, 17);
    osec = se;
  }
  delay(50);                // no es necesario poner este delay
}
void printNum(byte digit, byte leftAdjust) {
  for (row = 0; row < 4; row++) {
    lcd.setCursor(leftAdjust, row);
    for (col = digit * 3; col < digit * 3 + 3; col++) {
      lcd.write(pgm_read_byte( &bn[row][col]) );
    }
  }
}

void printColon(byte leftAdjust) {
  for (row = 0; row < 4; row++) {
    lcd.setCursor(leftAdjust, row);
    if (row == 1 || row == 2) lcd.print(F(".")); else lcd.print(F(" "));
  }
}
// ********************************************************************************** //
//                                      OPERATION ROUTINES
// ********************************************************************************** //
// FREERAM: Returns the number of bytes currently free in RAM
int freeRam(void) {
  extern int  __bss_end, *__brkval;
  int free_memory;
  if ((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end);
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval);
  }
  return free_memory;
}
//****************************************************************************************************************
void sectorActivo(int g) {
  //compruebo HORARIO y CONDICIONANTES
  //HORARIO: si hora !0:0 y TR!=0 y horario
  arraySActivo[g] = 0;
  for (int i = 4; i < 15; i += 2) {
    if (((progCon[g][i]) != 0) && ((progCon[g][3]) != 0) && (horaAc >= (progCon[g][i])) && (horaAc < (progCon[g][i + 1]))) {
      arraySActivo[g] = true;
    } else {
      if (!arraySActivo[g]) {
        arraySActivo[g] == false;
      }
    }
  }//for
  //CONDICIONANTES:riega si (invernadero y hora) o (!invernadero y !suspension y hora)
  if (((progCon[g][2]) && (arraySActivo[g])) || ((!(progCon[g][2])) && (!del) && (arraySActivo[g]))) {
    arrayS2[g] = true;
  }
  else {
    arrayS2[g] = false;
  }
}
void menu() {
  switch (mNivel1) {
    case 0:
      mainMenu(); //Hora etc
      break;
    case 1:
      manS();  //ARRANQUE MANUAL
      break;
    case 2:
      manS2();  //ARRANQUE MANUAL 2
      break;
    case 3:
      Delay();//RAIN DELAY, Suspender riego exterior(no invernadero) 6.12.24.48h
      break;
    case 4:
      setPorc();//PORCENTAJE DE RIEGO
      break;
    case 5:
      setHora ();//PONE EN HORA
      break;
    case 6:
      setProg ();//PROGRAMA
      break;
    case 7:
      borraP ();//BORRA PROGRAMACION
      break;
  }
}
//---------------------------------------------------------
//  Pantalla de INICIO                                  000
//---------------------------------------------------------
void mainMenu() {
 
  if (!cCount || !neW) {
    lcd.clear();
    neW = 1;
  }
  lcd.noBlink();
  lcd.setCursor(0, 0);
  if (IO) {
     
    lcd.print("<C<<<< INICIO >>>>D>");
  }
  if (!IO) {
    lcd.print("<C< # Activar # >D>");
  }
  if (now.hour() > 9) lcd.setCursor(0, 1);
  if (now.hour() < 10) lcd.setCursor(1, 1);
  lcd.print(now.hour() % 12, DEC);
  printDigits(now.minute());
  printDigits(now.second());

  lcd.setCursor(9, 1);
  lcd.print(int(rtc.getTemperature()));
  lcd.print(char(223));//imagenes google "char lcd"
  lcd.print("C");
  lcd.setCursor(14, 1);
  if (IO) {
    lcd.print("Activo");
  }
  if (!IO) {
    lcd.print("OFF OFF");
  }

  if (timer & 0x01) { //comprueba si es par
    lcd.setCursor(0, 2);

    if (arrayAM[1] > horaAc) {
      lcd.print("mON");
    } else if (arrayS2[1] == 1) {
      lcd.print("hON");
    } else {
      lcd.print("OFF");
    }
    lcd.setCursor(4, 2);
    if (arrayAM[2] > horaAc) {
      lcd.print("mON");
    } else if (arrayS2[2] == 1) {
      lcd.print("hON");
    } else {
      lcd.print("OFF");
    }
    lcd.setCursor(9, 2);
    if (arrayAM[3] > horaAc) {
      lcd.print("mON");
    } else if (arrayS2[3] == 1) {
      lcd.print("hON");
    } else {
      lcd.print("OFF");
    }
    lcd.setCursor(14, 2);
    if (arrayAM[4] > horaAc) {
      lcd.print("mON");
    } else if (arrayS2[4] == 1) {
      lcd.print("hON");
    } else {
      lcd.print("OFF");
    }
    lcd.setCursor(0, 3);
    if (arrayAM[5] > horaAc) {
      lcd.print("mON");
    } else if (arrayS2[5] == 1) {
      lcd.print("hON");
    } else {
      lcd.print("OFF");
    }
    lcd.setCursor(4, 3);
    if (arrayAM[6] > horaAc) {
      lcd.print("mON");
    } else if (arrayS2[6] == 1) {
      lcd.print("hON");
    } else {
      lcd.print("OFF");
    }
    lcd.setCursor(9, 3);
    if (arrayAM[7] > horaAc) {
      lcd.print("mON");
    } else if (arrayS2[7] == 1) {
      lcd.print("hON");
    } else {
      lcd.print("OFF");
    }
  } else {
    lcd.setCursor(0, 2);
    lcd.print("S1 ");
    lcd.setCursor(4, 2);
    lcd.print("S2 ");
    lcd.setCursor(9, 2);
    lcd.print("S3 ");
    lcd.setCursor(14, 2);
    lcd.print("S4 ");
    lcd.setCursor(0, 3);
    lcd.print("S5 ");
    lcd.setCursor(4, 3);
    lcd.print("S6 ");
    lcd.setCursor(9, 3);
    lcd.print("S7 ");
  }

  xKey();
  switch (key) {
    case 'D':
      mNivel1 = mNivel1 + 1;
      neW = 0;
      break;
    case 'C':
      mNivel1 = 7;
      break;
    case '*':
      IO = 0;
      break;
    case '#':
      IO = 1;
      break;
    case 'A':
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("C-D navega menu");
      lcd.setCursor(0, 1);
      lcd.print("A ayuda");
      lcd.setCursor(0, 2);
      lcd.print("# Activa programador");
      lcd.setCursor(0, 3);
      lcd.print("* Apaga riegos");
      lcd.setCursor(19, 3);
      lcd.print("5");
      delay(1000);
      lcd.setCursor(19, 3);
      lcd.print("4");
      delay(1000);
      lcd.setCursor(19, 3);
      lcd.print("3");
      delay(1000);
      lcd.setCursor(19, 3);
      lcd.print("2");
      delay(1000);
      lcd.setCursor(19, 3);
      lcd.print("1");
      break;
    default:
      break;
  }
  //    delay(200);
}
//---------------------------------------------------------
// ARRANQUE MANUAL                                      111
//---------------------------------------------------------
void manS() {
  if (!cCount || !neW) {
    lcd.clear();
    neW = 1;
  }
  lcd.noBlink();
  lcd.setCursor(0, 0);
  lcd.print("C<ARRANQUE MANUAL>D>");
  lcd.setCursor(0, 1);
  lcd.print("S");
  lcd.setCursor(0, 2);
  lcd.print("T");
  lcd.setCursor(0, 3);
  lcd.print("s");
  lcd.setCursor(3, 1);
  for (int i = 1; i < 8; i++) {
    arrayTAM[i] = progCon[i][3];
  }//tam tr
  lcd.print("1");
  lcd.setCursor(3, 2);
  lcd.print(arrayTAM[1]);
  lcd.setCursor(3, 3);
  if (arrayAM[1] > horaAc) {
    lcd.print("ON");
  }
  if (arrayAM[1] <= horaAc) {
    lcd.print("off");
  }
  lcd.setCursor(7, 1);
  lcd.print("2");
  lcd.setCursor(7, 2);
  lcd.print(arrayTAM[2]);
  lcd.setCursor(7, 3);
  if (arrayAM[2] > horaAc) {
    lcd.print("ON");
  }
  if (arrayAM[2] <= horaAc) {
    lcd.print("off");
  }
  lcd.setCursor(11, 1);
  lcd.print("3");
  lcd.setCursor(11, 2);
  lcd.print(arrayTAM[3]);//
  lcd.setCursor(11, 3);
  if (arrayAM[2] > horaAc) {
    lcd.print("ON");
  }
  if (arrayAM[3] <= horaAc) {
    lcd.print("off");
  }
  lcd.setCursor(15, 1);
  lcd.print("4");
  lcd.setCursor(15, 2);
  lcd.print(arrayTAM[4]);//
  lcd.setCursor(15, 3);
  if (arrayAM[4] > horaAc) {
    lcd.print("ON");
  }
  if (arrayAM[4] <= horaAc) {
    lcd.print("off");
  }
  xKey();
  switch (key) {
    case 'B':
    case '5':
    case '6':
    case '7':
      mNivel1 = mNivel1 + 1;
      neW = 0;
      break;
    case 'D':
      mNivel1 = mNivel1 + 2;
      neW = 0;
      break;
    case 'C':
      mNivel1 = mNivel1 - 1;
      neW = 0;
      break;
    case '1': //on-of S1
      if (arrayAM[1] >= horaAc) {
        arrayAM[1] = (horaAc - 2);
      }
      else if (arrayAM[1] < horaAc) {
        arrayAM[1] = horaAc + arrayTAM[1];
      }
      break;
    case '2': //on-of S2
      if (arrayAM[2] >= horaAc) {
        arrayAM[2] = (horaAc - 2);
      }
      else if (arrayAM[2] < horaAc) {
        arrayAM[2] = horaAc + arrayTAM[2];
      }
      break;
    case '3': //on-of S3
      if (arrayAM[3] >= horaAc) {
        arrayAM[3] = (horaAc - 2);
      }
      else if (arrayAM[3] < horaAc) {
        arrayAM[3] = horaAc + arrayTAM[3];
      }
      break;
    case '4': //on-of S4
      if (arrayAM[4] >= horaAc) {
        arrayAM[4] = (horaAc - 2);
      }
      else if (arrayAM[4] < horaAc) {
        arrayAM[4] = horaAc + arrayTAM[4];
      }
      break;
    case 'A':
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Num ON - OFF ");
      lcd.setCursor(0, 1);
      lcd.print("#edit -B (T) A +");
      lcd.setCursor(0, 2);
      lcd.print("izq C - D drcha ");
      lcd.setCursor(0, 3);
      lcd.print("* OFF  ON #(0=5min)");
      delay(5000);
      break;
    case '#':
      mNivel2 = 1;
      exiT = 0;
      while (!exiT) {
        lcd.blink();
        xKey();
        switch (mNivel2) {
          case 1:
            lcd.setCursor(3, 3);
            if (key == 'D') {
              mNivel2 = 2;
            }
            if (key == 'C') {
              mNivel2 = 4;
            }
            if (key == 'A') {
              arrayTAM[1] = arrayTAM[1] + 1;
              lcd.setCursor(3, 2);
              lcd.print(arrayTAM[1]);
            }
            if ((key == 'B') && (arrayTAM[1] > 0)) {
              arrayTAM[1] = arrayTAM[1] - 1;
              lcd.setCursor(3, 2);
              lcd.print(arrayTAM[1]);
            }
            if (key == '0' || key == '*') {
              arrayAM[1] = horaAc;
              exiT = 1;
            }
            if (key == '#') {
              if (arrayTAM[1] == 0) {
                arrayTAM[1] = 5;
              }
              arrayAM[1] = horaAc + arrayTAM[1];
              exiT = 1;
            }
            break;
          case 2:
            lcd.setCursor(7, 3);
            if (key == 'C') {
              mNivel2 = 1;
            }
            if (key == 'D') {
              mNivel2 = 3;
            }
            if (key == 'A') {
              arrayTAM[2] = arrayTAM[2] + 1;
              lcd.setCursor(7, 2);
              lcd.print(arrayTAM[2]);
            }
            if ((key == 'B') && (arrayTAM[2] > 0)) {
              arrayTAM[2] = arrayTAM[2] - 1;
              lcd.setCursor(7, 2);
              lcd.print(arrayTAM[2]);
            }
            if (key == '0' || key == '*') {
              arrayAM[2] = horaAc;
              exiT = 1;
            }
            if (key == '#') {
              if (arrayTAM[2] == 0) {
                arrayTAM[2] = 5;
              }
              arrayAM[2] = horaAc + arrayTAM[2];
              exiT = 1;
            }
            break;
          case 3:
            lcd.setCursor(11, 3);
            if (key == 'C') {
              mNivel2 = 2;
            }
            if (key == 'D') {
              mNivel2 = 4;
            }
            if (key == 'A') {
              arrayTAM[3] = arrayTAM[3] + 1;
              lcd.setCursor(11, 2);
              lcd.print(arrayTAM[3]);
            }
            if ((key == 'B') && (arrayTAM[3] > 0)) {
              arrayTAM[3] = arrayTAM[3] - 1;
              lcd.setCursor(11, 2);
              lcd.print(arrayTAM[3]);
            }
            if (key == '0' || key == '*') {
              arrayAM[3] = horaAc;
              exiT = 1;
            }
            if (key == '#') {
              if (arrayTAM[3] == 0) {
                arrayTAM[3] = 5;
              }
              arrayAM[3] = horaAc + arrayTAM[3];
              exiT = 1;
            }
            break;
          case 4:
            lcd.setCursor(15, 3);
            if (key == 'C') {
              mNivel2 = 3;
            }
            if (key == 'D') {
              mNivel2 = 1;
            }
            if (key == 'A') {
              arrayTAM[4] = arrayTAM[4] + 1;
              lcd.setCursor(15, 2);
              lcd.print(arrayTAM[4]);
            }
            if ((key == 'B') && (arrayTAM[4] > 0)) {
              arrayTAM[4] = arrayTAM[4] - 1;
              lcd.setCursor(15, 2);
              lcd.print(arrayTAM[4]);
            }
            if (key == '0' || key == '*') {
              arrayAM[4] = horaAc;
              exiT = 1;
            }
            if (key == '#') {
              if (arrayTAM[4] == 0) {
                arrayTAM[4] = 5;
              }
              arrayAM[4] = horaAc + arrayTAM[4];
              exiT = 1;
            }
            break;
          default:
            break;
        }//switch mNivel2
      }//While
      break;
  }//switch case
}
void manS2() { ////////////////////////////////////////////////ARRANQUE MANUAL 222222222222222
  if (!cCount || !neW) {
    lcd.clear();
    neW = 1;
  }
  lcd.noBlink();
  lcd.setCursor(0, 0);
  lcd.print("C<ARRANQUE MANUAL>D>");
  lcd.setCursor(0, 1);
  lcd.print("S");
  lcd.setCursor(0, 2);
  lcd.print("T");
  lcd.setCursor(0, 3);
  lcd.print("s");
  lcd.setCursor(3, 1);
  for (int i = 1; i < 8; i++) {
    arrayTAM[i] = progCon[i][3];
  }//tam tr
  lcd.print("5");
  lcd.setCursor(3, 2);
  lcd.print(arrayTAM[5]);
  lcd.setCursor(3, 3);
  if (arrayAM[5] > horaAc) {
    lcd.print("ON");
  }
  if (arrayAM[5] <= horaAc) {
    lcd.print("off");
  }
  lcd.setCursor(7, 1);
  lcd.print("6");
  lcd.setCursor(7, 2);
  lcd.print(arrayTAM[6]);
  lcd.setCursor(7, 3);
  if (arrayAM[6] > horaAc) {
    lcd.print("ON");
  }
  if (arrayAM[6] <= horaAc) {
    lcd.print("off");
  }
  lcd.setCursor(11, 1);
  lcd.print("7");
  lcd.setCursor(11, 2);
  lcd.print(arrayTAM[7]);//
  lcd.setCursor(11, 3);
  if (arrayAM[7] > horaAc) {
    lcd.print("ON");
  }
  if (arrayAM[7] <= horaAc) {
    lcd.print("off");
  }
  xKey();
  switch (key) {
    case 'D':
      mNivel1 = mNivel1 + 1;
      break;
    case 'A':
    case 'B':
    case '1':
    case '2':
    case '3':
    case '4':
      mNivel1 = mNivel1 - 1;
      neW = 0;
      break;
    case 'C':
      mNivel1 = mNivel1 - 2;
      neW = 0;
      break;
    case '5': //on-of S5
      if (arrayAM[5] >= horaAc) {
        arrayAM[5] = (horaAc - 2);
      }
      else if (arrayAM[5] < horaAc) {
        arrayAM[5] = horaAc + arrayTAM[5];
      }
      break;
    case '6': //on-of S6
      if (arrayAM[6] >= horaAc) {
        arrayAM[6] = (horaAc - 2);
      }
      else if (arrayAM[6] < horaAc) {
        arrayAM[6] = horaAc + arrayTAM[6];
      }
      break;
    case '7': //on-of S7
      if (arrayAM[7] >= horaAc) {
        arrayAM[7] = (horaAc - 2);
      }
      else if (arrayAM[7] < horaAc) {
        arrayAM[7] = horaAc + arrayTAM[7];
      }
      break;
    case '#':
      mNivel2 = 1;
      while (!exiT) {
        lcd.blink();
        xKey();
        switch (mNivel2) {
          case 1:
            lcd.setCursor(3, 3);
            if (key == 'D') {
              mNivel2 = 2;
            }
            if (key == 'C') {
              mNivel2 = 3;
            }
            if (key == 'A') {
              arrayTAM[5] = arrayTAM[5] + 1;
              lcd.setCursor(3, 2);
              lcd.print(arrayTAM[5]);
            }
            if ((key == 'B') && (arrayTAM[5] > 0)) {
              arrayTAM[5] = arrayTAM[5] - 1;
              lcd.setCursor(3, 2);
              lcd.print(arrayTAM[5]);
            }
            if (key == '0' || key == '*') {
              arrayAM[5] = horaAc;
              exiT = 1;
            }
            if (key == '#') {
              if (arrayTAM[5] == 0) {
                arrayTAM[5] = 5;
              }
              arrayAM[5] = horaAc + arrayTAM[5];
              exiT = 1;
            }
            break;
          case 2:
            lcd.setCursor(7, 3);
            if (key == 'C') {
              mNivel2 = 1;
            }
            if (key == 'D') {
              mNivel2 = 3;
            }
            if (key == 'A') {
              arrayTAM[6] = arrayTAM[6] + 1;
              lcd.setCursor(7, 2);
              lcd.print(arrayTAM[6]);
            }
            if ((key == 'B') && (arrayTAM[6] > 0)) {
              arrayTAM[6] = arrayTAM[6] - 1;
              lcd.setCursor(7, 2);
              lcd.print(arrayTAM[6]);
            }
            if (key == '0' || key == '*') {
              arrayAM[6] = horaAc;
              exiT = 1;
            }
            if (key == '#') {
              if (arrayTAM[6] == 0) {
                arrayTAM[6] = 5;
              }
              arrayAM[6] = horaAc + arrayTAM[6];
              exiT = 1;
            }
            break;
          case 3:
            lcd.setCursor(11, 3);
            if (key == 'C') {
              mNivel2 = 2;
            }
            if (key == 'D') {
              mNivel2 = 1;
            }
            if (key == 'A') {
              arrayTAM[7] = arrayTAM[7] + 1;
              lcd.setCursor(15, 2);
              lcd.print(arrayTAM[7]);
            }
            if ((key == 'B') && (arrayTAM[7] > 0)) {
              arrayTAM[7] = arrayTAM[7] - 1;
              lcd.setCursor(15, 2);
              lcd.print(arrayTAM[7]);
            }
            if (key == '0' || key == '*') {
              arrayAM[7] = horaAc;
              exiT = 1;
            }
            if (key == '#') {
              if (arrayTAM[7] == 0) {
                arrayTAM[7] = 5;
              }
              arrayAM[7] = horaAc + arrayTAM[7];
              exiT = 1;
            }
            break;
          default:
            break;
        }
      }//While
      break;
  }//switch case
}
//---------------------------------------------------------
// SUSPENSION EXTERIOR                                  333
//---------------------------------------------------------
void Delay() {
  lcd.noBlink();
  lcd.setCursor(0, 0);
  lcd.print("<C<< SUSPENSION >>D>");
  lcd.setCursor(0, 1);
  lcd.print("Riego exterior");
  if (del == 0) {
    lcd.setCursor(0, 2);
    lcd.print("     activado");
    lcd.setCursor(0, 3);
    lcd.print("+A,#   -B   *=0");
  } else if (del == 24) {
    lcd.setCursor(0, 2);
    lcd.print("suspendido 1 dia");
    lcd.setCursor(0, 3);
    lcd.print("+A,#   -B   *=0");
  } else if (del == 48) {
    lcd.setCursor(0, 2);
    lcd.print("suspendido 2 dias");
    lcd.setCursor(0, 3);
    lcd.print("+A,#   -B   *=0");
  } else if (del == 72) {
    lcd.setCursor(0, 2);
    lcd.print("suspendido 3 dias");
    lcd.setCursor(0, 3);
    lcd.print("+A,#   -B   *=0");
  } else if (del > 0 && del < 72) { //err 254
    lcd.setCursor(0, 2);
    lcd.print("suspendido ");
    lcd.print(del);
    lcd.print(" horas");
    lcd.setCursor(0, 3);
    lcd.print("+A,#   -B   *=0");
  } else if (del > 72) {
    lcd.setCursor(0, 2);
    lcd.print("    SUSPENDIDO");
    lcd.setCursor(0, 3);
    lcd.print(" INDEFINIDAMENTE *");
  }
  xKey();
  switch (key) {
    case 'D':
      mNivel1 = mNivel1 + 1;
      break;
    case 'C':
      mNivel1 = mNivel1 - 2;
      break;
    case'#':
    case 'A':
      if (del < 84)del = del + 12;
      break;
    case'B':
      if (del <= 12 && del > 0) {
        del = del - 4;
      } else if (del <= 4 && del > 0) {
        del = del - 1;
      } else if (del > 12) {
        del = del - 12;
      }
      break;
    case '*':
      del = 0;
      break;
    default:
      break;
  }//switch key
}
//---------------------------------------------------------
// SET PORCENTAJE                                             444
//---------------------------------------------------------
void setPorc() {
  lcd.noBlink();
  xKey();
  lcd.setCursor(0, 0);
  lcd.print("C<<SET PORCENTAJE>>D");
  lcd.setCursor(0, 1);
  lcd.print(" valido 10% a 250%");
  lcd.setCursor(1, 3);
  lcd.print("-B (");
  lcd.print(porc);
  lcd.print("% de T) A+");
  switch (key) {
    case 'D':
      mNivel1 = mNivel1 + 1;
      neW = 1;
      break;
    case 'C':
      mNivel1 = mNivel1 - 1;
      break;
    case '#':
    case 'A':
      if (porc < 250) {
        porc = porc + 10;
        syncProg();
      }
      break;
    case 'B':
      if (porc > 10) {
        porc = porc - 10;
        syncProg();
      }
      break;
    case '*':
      porc = 100;
      break;
  }
}
//---------------------------------------------------------
// SET HORA                                            666
//---------------------------------------------------------
void setHora () {
  int f;
  char string[] = "0 :  ";
  if (!cCount || !neW) {
    lcd.clear();
    neW = 1;
  }
  lcd.setCursor(0, 0);
  lcd.print("<C<<< SET HORA >>>D>");
  lcd.setCursor(0, 1);
  lcd.print("Actual" );
  if (now.hour() > 9) lcd.setCursor(8, 1);
  if (now.hour() < 10) lcd.setCursor(9, 1);
  lcd.print(now.hour(), DEC);
  printDigits(now.minute());
  lcd.setCursor(0, 3);
  lcd.print("num *cancel #save");
  lcd.setCursor(0, 2);
  lcd.print("new     ");
  lcd.print (iH);
  lcd.setCursor(8 + f, 2);
  lcd.blink();
  xKey();
  switch (key) {
    case 'D':
      mNivel1 = mNivel1 + 1;
      neW = 0;
      break;
    case 'C':
      mNivel1 = mNivel1 - 1;
      break;
    case '0':
    case '1':
    case '2':
      lastKey = key;
      introH(2);///////no vale asignar valores dentro de la funcion
      ihh = (((buffer[0] - '0') * 10) + (buffer[1] - '0'));
      imm = (((buffer[2] - '0') * 10) + (buffer[3] - '0'));
      if (0 > ihh > 23) {
        ihh = 0;
      }
      if (0 >= ihh > 59) {
        imm = 0;
      }
      if (ihh != 0 && imm != 0) {
        gHora();
      }
      clearBuffer();
      break;
  }//switch key
}
void gHora() {
  DateTime dt(2015, 1, 1, ihh, imm, 0, 0);
  rtc.setDateTime(dt) ;//year, month, date, hour, min, sec and week-day(starts from 0(sunday) and goes to 6)
}
//---------------------------------------------------------
// SET PROGRAMA                                        777
//---------------------------------------------------------
void setProg () {
  if (!cCount || !neW) {
    lcd.clear();
    neW = 1;
  }
  lcd.noBlink();
  lcd.setCursor(0, 0);
  lcd.print("<C<<< PROGRAMA >>>D>");
  lcd.setCursor(0, 1);
  lcd.print("S");
  lcd.print(s);
  lcd.setCursor(3, 1);
  if (progRec[s][3] == 0) {
    lcd.print("OFF");
  }
  if (progRec[s][3] != 0) {
    lcd.print("ON");
  }
  lcd.setCursor(7, 1);
  lcd.print("TR ");
  lcd.print(progRec[s][3]);
  lcd.setCursor(13, 1);
  lcd.print("Inv?");
  lcd.print(progRec[s][2]);

  lcd.setCursor(0, 2);
  lcd.print(progRec[s][4]);
  printDigits(progRec[s][5]);
  lcd.setCursor(6, 2);
  lcd.print(progRec[s][6]);
  printDigits(progRec[s][7]);
  lcd.setCursor(12, 2);
  lcd.print(progRec[s][8]);
  printDigits(progRec[s][9]);

  lcd.setCursor(0, 3);
  lcd.print(progRec[s][10]);
  printDigits(progRec[s][11]);
  lcd.setCursor(6, 3);
  lcd.print(progRec[s][12]);
  printDigits(progRec[s][13]);
  lcd.setCursor(12, 3);
  lcd.print(progRec[s][14]);
  printDigits(progRec[s][15]);

  xKey();
  switch (key) {
    case 'D':
      mNivel1 = mNivel1 + 1;
      break;
    case 'C':
      mNivel1 = mNivel1 - 1;
      neW = 0;
      break;
    case 'A':
      if (s == 1) {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("T en  minutos <99");
        lcd.setCursor(0, 1);
        lcd.print("Num A B sector");
        lcd.setCursor(0, 2);
        lcd.print(" # editar");
        lcd.setCursor(0, 3);
        lcd.print(" * # salir");
        delay(5000);
      }
      if (s > 1) {
        s = s - 1;
      }
      break;
    case 'B':
      if (s < 7) {
        s = s + 1;
      }
      break;
    case '1':
      s = 1;
      break;
    case '2':
      s = 2;
      break;
    case '3':
      s = 3;
      break;
    case '4':
      s = 4;
      break;
    case '5':
      s = 5;
      break;
    case '6':
      s = 6;
      break;
    case '7':
      s = 7;
      break;
    case '#':
      mNivel2 = 1;
      while (key != '*') {
        xKey();
        switch (mNivel2) {
          case 1:                   //set Tiempo de riego//////hacer funcion settr
            lcd.setCursor(10, 1);
            lcd.blink();
            if (key == 'D') {
              mNivel2 = 2;
            }
            if (key == 'B') {
              mNivel2 = 4;
            }
            if (key == '#') {
              return;
            }
            if (validKeys0to9(key)) {
              storeKey(key);
              progRec[s][3] = buffer[0] - '0';
              lcd.print(buffer[0]);
              key = customKeypad.waitForKey();
              if (validKeys0to9(key)) {
                storeKey(key);
                progRec[s][3] = int(((buffer[0] - '0') * 10) + (buffer[1] - '0'));
                lcd.setCursor(10, 1);
                lcd.print(progRec[s][3]);
              }
              if (key == 'D') {
                lcd.print(" ");
              }
              if (key == '#') {
                lcd.print(" ");
                return;
              }
              clearBuffer();
              mNivel2 = 2;
            }
            if (key == 'D') {
              mNivel2 = 2;
            }
            break;
          case 2:          //set inernadero
            lcd.setCursor(17, 1);
            if (key == 'C') {
              mNivel2 = 1;
            }
            if (key == 'B') {
              mNivel2 = 5;
            }
            if (validKeys0to1(key)) {
              progRec[s][2] = key - '0';
              lcd.print(key);
              mNivel2 = 3;
            }
            if (key == 'D') {
              mNivel2 = 3;
            }
            if (key == '#') {
              return;
            }
            break;
          case 3:                           //set H1
            lcd.setCursor(0, 2);
            if (key == 'A') {
              mNivel2 = 1;
            }
            if (key == 'B') {
              mNivel2 = 6;
            }
            if (key == 'C') {
              mNivel2 = 2;
            }
            if (key == 'D') {
              mNivel2 = 4;
            }
            if (key == '#') {
              return;
            }
            if (validKeys0to2(key)) {
              lastKey = key;
              introH(0);///////no vale asignar valores dentro de la funcion
              progRec[s][4] = (((buffer[0] - '0') * 10) + (buffer[1] - '0'));
              progRec[s][5] = (((buffer[2] - '0') * 10) + (buffer[3] - '0'));
              if (progRec[s][4] > 23) {
                progRec[s][4] = 0;
              }
              if (progRec[s][5] > 59) {
                progRec[s][5] = 0;
              }
              clearBuffer();
            }
            break;
          case 4:                           //set H2
            lcd.setCursor(6, 2);
            if (key == 'A') {
              mNivel2 = 1;
            }
            if (key == 'B') {
              mNivel2 = 7;
            }
            if (key == 'C') {
              mNivel2 = 3;
            }
            if (key == 'D') {
              mNivel2 = 5;
            }
            if (key == '#') {
              return;
            }
            if (validKeys0to2(key)) {
              lastKey = key;
              introH(1);
              progRec[s][6] = (((buffer[0] - '0') * 10) + (buffer[1] - '0'));
              progRec[s][7] = (((buffer[2] - '0') * 10) + (buffer[3] - '0'));
              if (progRec[s][6] > 23) {
                progRec[s][6] = 0;
              }
              if (progRec[s][7] > 59) {
                progRec[s][7] = 0;
              }
              clearBuffer();
            }
            break;
          case 5: //set H3
            lcd.setCursor(12, 2);
            if (key == 'A') {
              mNivel2 = 2;
            }
            if (key == 'B') {
              mNivel2 = 8;
            }
            if (key == 'C') {
              mNivel2 = 4;
            }
            if (key == 'D') {
              mNivel2 = 6;
            }
            if (key == '#') {
              return;
            }
            if (validKeys0to2(key)) {
              lastKey = key;
              introH(2);
              progRec[s][8] = (((buffer[0] - '0') * 10) + (buffer[1] - '0'));
              progRec[s][9] = (((buffer[2] - '0') * 10) + (buffer[3] - '0'));
              if (progRec[s][8] > 23) {
                progRec[s][8] = 0;
              }
              if (progRec[s][9] > 59) {
                progRec[s][9] = 0;
              }
              clearBuffer();
            }
            break;
          case 6: //set H4
            lcd.setCursor(0, 3);
            if (key == 'A') {
              mNivel2 = 3;
            }
            if (key == 'C') {
              mNivel2 = 5;
            }
            if (key == 'D') {
              mNivel2 = 7;
            }
            if (key == '#') {
              return;
            }
            if (validKeys0to2(key)) {
              lastKey = key;
              introH(3);
              progRec[s][10] = (((buffer[0] - '0') * 10) + (buffer[1] - '0'));
              progRec[s][11] = (((buffer[2] - '0') * 10) + (buffer[3] - '0'));
              if (progRec[s][10] > 23) {
                progRec[s][10] = 0;
              }
              if (progRec[s][11] > 59) {
                progRec[s][11] = 0;
              }
              clearBuffer();
            }
            break;
          case 7: //set H5
            lcd.setCursor(6, 3);
            if (key == 'A') {
              mNivel2 = 4;
            }
            if (key == 'C') {
              mNivel2 = 6;
            }
            if (key == 'D') {
              mNivel2 = 8;
            }
            if (key == '#') {
              return;
            }
            if (validKeys0to2(key)) {
              lastKey = key;
              introH(4);
              progRec[s][12] = (((buffer[0] - '0') * 10) + (buffer[1] - '0'));
              progRec[s][13] = (((buffer[2] - '0') * 10) + (buffer[3] - '0'));
              if (progRec[s][12] > 23) {
                progRec[s][12] = 0;
              }
              if (progRec[s][13] > 59) {
                progRec[s][13] = 0;
              }
              clearBuffer();
            }
            break;
          case 8: //set H6
            lcd.setCursor(12, 3);
            if (key == 'A') {
              mNivel2 = 5;
            }
            if (key == 'C') {
              mNivel2 = 7;
            }
            if (key == 'D') {
              mNivel2 = 9;
            }
            if (key == '#') {
              return;
            }
            if (validKeys0to2(key)) {
              lastKey = key;
              introH(2);
              progRec[s][14] = (((buffer[0] - '0') * 10) + (buffer[1] - '0'));
              progRec[s][15] = (((buffer[2] - '0') * 10) + (buffer[3] - '0'));
              if (progRec[s][14] > 23) {
                progRec[s][14] = 0;
              }
              if (progRec[s][15] > 59) {
                progRec[s][15] = 0;
              }
              clearBuffer();
              mNivel2 = 9;
            }
            break;
          case 9:
            return;
            break;
          default:
            break;
        }//switch(SPState)
      }//while (key!='*')
  }//switch
}
void introH(int nh) {                                     //intro hora
  int state = 1;
  lcd.print (lastKey);
  storeKey(lastKey);
  exiT = 0;
  while (!exiT) {
    xKey ();
    switch (state) {
      case 1://1ºdigito ya viene
        if (lastKey == 2 && validKeys0to3(key)) {
          lcd.print(key);
          storeKey(key);
          state = 2;
        } else if (lastKey != 2 && validKeys0to9(key)) {
          lcd.print(key);
          storeKey(key);
          state = 2;
        } else if (key == 'D' || key == '#') {
          state = 2;
        } else if (key == '*') {
          clearBuffer();
          exiT = 1;
        }
        break;
      case 2:
        lcd.print(":");
        state = 3;
        break;
      case 3:   //minuto1º
        if (validKeys0to5(key)) {
          storeKey(key);
          lcd.print(key);
          state = 4;
        } else if (key == '*') {
          clearBuffer();
          exiT = 1;
        }
        break;
      case 4://min2
        if (validKeys0to9(key)) {
          lcd.print(key);
          storeKey(key);
          state = 5;//acepta o descarta
        } else if (key == 'C') {
          state = 5;
        } else if (key == '*') {
          clearBuffer();
          exiT = 1;
        }
        break;
      case 5://no vale asignar los valores aqui
        //progRec[ss][nh+4]= (((buffer[0]-'0')*10)+(buffer[1]-'0'));
        //progRec[ss][nh+5]= (((buffer[2]-'0')*10)+(buffer[3]-'0'));
        //clearBuffer();
        mNivel2 = nh + 4;
        return;//sale a
        break;
      default:
        break;
    }//switch
  }//while
  clearBuffer();
}
void clearBuffer(void) {//podria vaciarse con '0' y no '\0'
  buffer[0] = '0';     //evitaria valor negativo al restar '0'
  buffer[1] = '0';
  buffer[2] = '0';
  buffer[3] = '0';
  index = 0;
}// Store key in buffer
void storeKey(char key) {
  buffer[index] = key;
  index++;
}
//---------------------------------------------------------
// BORRA/GUARDA PROGAMA EN EEPROM                       777
//---------------------------------------------------------
void borraP () {
  int a;
  int b;
  lcd.noBlink();
  lcd.setCursor(0, 0);
  lcd.print("<C< BORRA/SALVA >>D>");
  lcd.setCursor(7, 1);
  lcd.print("EEPROM");
  lcd.setCursor(0, 2);
  lcd.print("* Borra  Guarda #");
  lcd.setCursor(3, 3);
  lcd.print(EPROMcount);
  lcd.print(" usos");

  xKey();
  switch (key) {
    case 'D':
      mNivel1 = 0;
      neW = 0;
      break;
    case 'C':
      mNivel1 = mNivel1 - 1;
      neW = 0;
      break;
    case 'A':
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("guarda programa");
      lcd.setCursor(0, 1);
      lcd.print("en memoria interna");
      lcd.setCursor(0, 2);
      lcd.print("estara disponible");
      lcd.setCursor(0, 3);
      lcd.print("despues de reiniciar");
      delay(6000);
      break;
    case 'B':
      break;
    case '*':
      for (a = 1; a < 8; a++) { //dejo s0
        for (b = 1; b < 16; b++) { //dejo index
          progRec[a][b] = 0;
        }
      }
      eepromWrite();
      syncProg();
      lcd.setCursor(0, 2);
      lcd.print("   borrando.....   ");
      delay(3000);
      break;
    case '#':
      eepromWrite();
      syncProg();
      lcd.setCursor(0, 3);
      lcd.print("   Guardando.....   ");
      delay(3000);
      break;
  }
  delay(100);
}
void syncProg() { //en minuto del dia max 1440 =24*60
  for (int i = 1; i < 8; i++) {
    progCon[i][2] = progRec[i][2]; //inv
    progCon[i][3] = progRec[i][3]; //Tr
    progCon[i][4] = ((progRec[i][4] * 60) + (progRec[i][5])); //h1-inicial " en minutos"
    progCon[i][5] = int((progCon[i][4]) + ((progRec[i][3]) * (porc / 100))); //h1 final
    progCon[i][6] = ((progRec[i][6] * 60) + progRec[i][7]); //h1-inicial
    progCon[i][7] = int((progCon[i][6]) + ((progRec[i][3]) * (porc / 100))); //h1 final
    progCon[i][8] = ((progRec[i][8] * 60) + progRec[i][9]); //h1-inicial
    progCon[i][9] = int((progCon[i][8]) + ((progRec[i][3]) * (porc / 100))); //h1 final
    progCon[i][10] = ((progRec[i][10] * 60) + progRec[i][11]); //h1-inicial
    progCon[i][11] = int((progCon[i][10]) + ((progRec[i][3]) * (porc / 100))); //h1 final
    progCon[i][12] = ((progRec[i][12] * 60) + progRec[i][13]); //h1-inicial
    progCon[i][13] = int((progCon[i][12]) + ((progRec[i][3]) * (porc / 100))); //h1 final
    progCon[i][14] = ((progRec[i][14] * 60) + progRec[i][15]); //h1-inicial
    progCon[i][15] = int ((progCon[i][14]) + ((progRec[i][3]) * (porc / 100))); //h1 final
  }

}
void eepromWrite() {
  int address = 0;
  for (int i = 1; i < 8; i++) {
    for (int j = 3; j < 16; j++) {
      EEPROM.writeInt(address, progRec[i][j]);
      address += 2;
    }
  }
  EEPROM.writeInt(298, (EPROMcount + 1));
  EPROMcount = EPROMcount + 1;
}
void eepromRead() {
  int address = 0;
  for (int i = 1; i < 8; i++) {
    for (int j = 3; j < 16; j++) {
      progRec[i][j] = EEPROM.readInt(address);
      address += 2;
    }
  }
  EPROMcount = (EEPROM.readInt(298) + 1);
}
/////////////////////////////////////////////////////
//necesario para contador backlight última pulsación
void xKey() {
  key = customKeypad.getKey();
  if (key != resetKey) {
    timer = 0;
    if (mNivel1 == 7 || mNivel1 == 4 || mNivel1 == 3) {
      lcd.clear();
    }
  }
  resetKey = key;
}
//////////////////////////////////imprime minutos :00
void printDigits(byte digits) {
  lcd.print(":");
  if (digits < 10) {
    lcd.print('0');
    lcd.print(digits, DEC);
  }
  else {
    lcd.print(digits, DEC);
  }
}
///////////////////////////////validaciones de teclas
// Validate keys: 0-9
// return true if valid, else false
int validKeys0to9(int key) {
  int valid = 0;
  switch (key) {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      valid = 1;
      break;
  }
  return valid;
}
// Validate keys: 0-5
int validKeys0to5(int key) {
  int valid = 0;
  switch (key) {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
      valid = 1;
      break;
  }
  return valid;
}
// Validate keys: 0-4
int validKeys0to3(int key) {
  int valid = 0;
  switch (key) {
    case '0':
    case '1':
    case '2':
    case '3':
      valid = 1;
      break;
  }
  return valid;
}
// Validate keys: 0-2
// return true if valid, else false
int validKeys0to2(int key) {
  int valid = 0;
  switch (key) {
    case '0':
    case '1':
    case '2':
      valid = 1;
      break;
  }
  return valid;
}
// Validate keys: 0-1
// return true if valid, else false
int validKeys0to1(int key) {
  int valid = 0;
  switch (key) {
    case '0':
    case '1':
      valid = 1;
      break;
  }
  return valid;
}

Hola.

Pues despues de partirme la cabeza intentando solucionar algun problema , he podido solucionar uno de ellos.

1 problema: Solucionado
Lo que quiero hacer es que en la pantalla de inicio del control riego, esté primeramente el bigreloj y cambie a la pantalla principal del control riego cuando se aprieta un boton del keypad 4x4

La verdad que la respuesta estaba en el mismo sketch y pido disculpas por ello,como bien dice Surbyte, gran moderador de este sitio, """" sin peloteo """", hay que mirar bien ,pues haciendo un buen repaso mentalmente del sketch en el trabajo,vino la solución.

Cada 15 segundos ( expuesto en el sketch como ejemplo por acortar tiempos de pruebas ) , entre en la pantalla de " bigreloj ", para ello he puesto una parte mas en el menú ( opción 8 ) y a partir de aqui hago el llamamiento a dicho menu ;
transcurridos 20 segundos que apague el lcd , hasta aquí esta todo correcto.

ahora solo me queda el tema de los caracteres raros del " bigreloj ",es raro ya que en el sketch original de dicho reloj,funciona bien.
Dejo la modificación por si alguien le pasa como a mi, pues tenga algo.
Repito,los pocos segundos es solo para pruebas.

Sketch reformado

 //control lcd.backlight
  if (now.second() != lastSecond) {
    timer++;
    lastSecond = now.second();
  }
  if (timer > 15 && !(arrayS[1] || arrayS[2] || arrayS[3] || arrayS[4] || arrayS[5] || arrayS[6] || arrayS[7] || arrayS[8])) {
    // lcd.noBacklight();
    mNivel1 = 8; // tras 15 segundos de inactividad pasa a pantalla BIG RELOJ
  }
  if (timer > 20 && !(arrayS[1] || arrayS[2] || arrayS[3] || arrayS[4] || arrayS[5] || arrayS[6] || arrayS[7] || arrayS[8])) {
     lcd.noBacklight(); // transcurridos 20 segundos de inactividad apaga lcd
     } else {   // si se aprieta cualquier boton enciende lcd
    lcd.backlight();
  }

Sketch original

 //control lcd.backlight
  if (now.second() != lastSecond) {
    timer++;
    lastSecond = now.second();
  }
  if (timer > 60 && !(arrayS[1] || arrayS[2] || arrayS[3] || arrayS[4] || arrayS[5] || arrayS[6] || arrayS[7])) {
      lcd.noBacklight();
  } else {
    lcd.backlight();
  }

Nuevamente pido disculpas por si alguno lo vio claro desde el primer momento, yo con mis pocas nociones hago lo que puedo y después de probar y leer,tenia un lio tremendo,jjjj