munther_abdellatif

fast_mode_3_20_06_2020

Jun 20th, 2020
71
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // function
  2. void getKey();
  3. void shift_serial_test();
  4. void RTC_LCD__test();
  5. void valvecontrol();
  6. void setclock();
  7. void lcddisplay();
  8. void load();
  9. void save();
  10. void valvereset();
  11. void progreset();
  12. void checkprog();
  13. void runprogfun();
  14. void shiftout();
  15. void saverunprogdata();
  16. void loadrunprogdata();
  17. void check_off_timer();
  18. void fastcheck();
  19. void stopprog();
  20. void continueprog();
  21. void saveday();
  22. void loadday();
  23. void stopall();
  24.  
  25. // eeprom
  26. #include<EEPROM.h>
  27. byte savedone=0;
  28. byte eedata=0;
  29. // keypad
  30. #include <Wire.h>
  31. byte input=0;
  32. byte lastInput1=0,lastInput2=0,lastInput3=0,lastInput4=0;
  33. byte key=16; //10>>A 11>>B 12>>C 13>>D 14>>* 15>>#
  34.  
  35. // shift reg
  36.  
  37. byte clk=D3,latch=D4,data=D0;
  38. byte dataout1=0b11111111;
  39. byte dataout2=0b11111111;
  40. byte dataout3=0b00001111;
  41. byte x=0;
  42. byte r=0;
  43.  
  44. //lcd
  45. #include<Wire.h>
  46. #include <LiquidCrystal_I2C.h>
  47. LiquidCrystal_I2C lcd (0x27,20,4);
  48.  
  49. // display
  50. byte pointer1=0,pointer2=0,pointer3=0;
  51. byte number1=0,number2=0,number3=0;
  52. bool timedis=0;
  53. bool main_page_data=0;
  54.  
  55. // valves data
  56. byte valvenum=1;
  57. byte valvedu[10]={0,0,0,0,0,0,0,0,0,0};
  58. byte valvePH[10]={0,0,0,0,0,0,0,0,0,0};
  59. byte valveCE[10]={0,0,0,0,0,0,0,0,0,0};
  60. byte fer1per[10]={0,0,0,0,0,0,0,0,0,0};
  61. byte fer2per[10]={0,0,0,0,0,0,0,0,0,0};
  62. byte fer3per[10]={0,0,0,0,0,0,0,0,0,0};
  63. byte fer4per[10]={0,0,0,0,0,0,0,0,0,0};
  64. byte fer5per[10]={0,0,0,0,0,0,0,0,0,0};
  65.  
  66. // test valve
  67. byte testvalve=0;
  68. bool valvestatus[10]={0,0,0,0,0,0,0,0,0,0};
  69.  
  70. // program data
  71. byte prognum=1;
  72. bool progact[25]={0,0,0,0,1,1,0,1,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0};
  73. bool progday1[25]={0,0,0,0,1,0,0,1,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0};//S
  74. bool progday2[25]={0,0,0,0,1,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0};//M
  75. bool progday3[25]={0,0,1,0,1,1,0,1,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0};//T
  76. bool progday4[25]={0,0,0,0,0,1,0,1,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0};//W
  77. bool progday5[25]={0,0,0,0,1,1,0,1,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0};//T
  78. bool progday6[25]={0,0,0,0,1,1,0,1,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0};//F
  79. bool progday7[25]={0,0,1,0,0,1,0,1,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0};//S
  80. byte proghour[25]={0,0,0,0,12,10,0,4,0,0,8,1,0,1,0,1,0,1,0,1,0,1,0,1,0}; //hour
  81. byte progmin[25] ={0,0,15,0,30,1,0,1,0,0,10,1,0,15,0,1,0,31,0,1,0,1,0,1,0}; //min
  82. byte progvalve=0;
  83. bool progvalve1[25]={0,0,0,0,1,0,0,1,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0};
  84. bool progvalve2[25]={0,0,0,0,1,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0};
  85. bool progvalve3[25]={0,0,1,0,1,1,0,1,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0};
  86. bool progvalve4[25]={0,0,0,0,0,1,0,1,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0};
  87. bool progvalve5[25]={0,0,0,0,1,1,0,1,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0};
  88. bool progvalve6[25]={0,0,0,0,1,1,0,1,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0};
  89. bool progvalve7[25]={0,0,1,0,0,1,0,1,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0};
  90. bool progvalve8[25]={0,1,0,0,1,1,0,1,0,0,1,1,0,1,0,1,0,0,0,1,0,1,0,1,0};
  91. bool progvalve9[25]={0,0,0,0,1,1,0,1,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,0,0};
  92. bool progvalve10[25]={0,0,0,0,1,1,0,1,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0};
  93.  
  94. // run prog
  95. byte valverun=0;
  96. byte valvetimer[10]={0,0,0,0,0,0,0,0,0,0};
  97. bool on_off_timer=0;
  98. byte on_timer=0;
  99. int  off_timer=0;
  100. unsigned long lastmillis=0;
  101. unsigned long lastmillis1=0;
  102.  
  103. // system on off timer
  104. byte progyear=0;
  105. byte progmonth=0;
  106. byte progday=0;
  107. byte progh=0;
  108. byte progm=0;
  109. bool fastmode=0;
  110. bool progsta=0;// 0>>starting 1>>paused
  111.  
  112. // test prog
  113. byte testprog=0,runprog=0;
  114.  
  115. // set clock
  116. byte setyear=20,setmonth=12,setday=6,sethour=17,setmin=29;
  117. // timer
  118. #include <PCF8563.h>
  119. PCF8563 pcf;
  120. byte day =5;
  121. String dayStr[7]={"Sunday","Monday","Tuesday","Wednesday","Thuresday","Friday","Saturday"};
  122. byte RTCday=0;
  123. byte lastRTCday=0;
  124. byte RTCsec=0;
  125. byte lastRTCsec=0;
  126. byte seccounter=0;
  127. byte RTCmin=0;
  128. byte lastRTCmin=0;
  129.  
  130. void setup() {
  131.   // pin
  132.   pinMode(clk, OUTPUT); pinMode(latch, OUTPUT) ; pinMode(data, OUTPUT);
  133.   Serial.begin(9600);
  134.    // shift reg
  135.   digitalWrite(latch,0);
  136.   shiftOut(data,clk,MSBFIRST,dataout3);
  137.   shiftOut(data,clk,MSBFIRST,dataout2);
  138.   shiftOut(data,clk,MSBFIRST,dataout1);
  139.   digitalWrite(latch,1);
  140.  
  141.  //timer
  142.   pcf.init();//initialize the clock
  143.   pcf.stopClock();//stop the clock
  144.   //set time
  145. /*pcf.setYear(20);//set year
  146.   pcf.setMonth(12);//set month
  147.   pcf.setDay(6);//set dat
  148.   pcf.setHour(17);//set hour
  149.   pcf.setMinut(29);//set minut
  150.   pcf.setSecond(50);//set second*/
  151.   pcf.startClock();//start the clock
  152.    Time nowTime = pcf.getTime();//get current time
  153.    RTCday=nowTime.day;
  154.    lastRTCday=RTCday;
  155.    RTCsec=nowTime.second;
  156.    lastRTCsec=RTCsec;
  157.    RTCmin=nowTime.minute;
  158.    lastRTCmin=RTCmin;
  159.    
  160.    //lcd
  161.   lcd.init();
  162.   lcd.backlight();
  163.   lcd.clear();
  164.   lcd.print (" loading data ");
  165.   // eeprom
  166.   EEPROM.begin(1024);
  167.   load();
  168.   // key pad
  169.   Wire.begin();
  170.   Wire.beginTransmission(0x20);
  171.   Wire.write(0x00);      // IO0dir reg port A
  172.   Wire.write(0xff);      // input
  173.   Wire.endTransmission();
  174.   Wire.begin();
  175.   Wire.beginTransmission(0x20);
  176.   Wire.write(0x01);      // IO0dir reg port B
  177.   Wire.write(0x00);      // output
  178.   Wire.endTransmission();
  179.   Wire.beginTransmission(0x20);
  180.   Wire.write(0x0C);      // pull up res port A
  181.   Wire.write(0xff);      
  182.   Wire.endTransmission();
  183.   // load last prog data
  184.   loadrunprogdata();
  185.   lcd.clear();
  186.   // load day
  187.   loadday();
  188. }
  189.  
  190. void loop() {
  191.   // RTC_LCD__test();
  192.   shift_serial_test ();
  193.   getKey();
  194.   lcddisplay();
  195.  
  196.   if      (progsta==0){      
  197.   if      (runprog==0 && fastmode==0){ checkprog();saverunprogdata();}
  198.   else if (runprog==0 && fastmode==1){ fastcheck();}
  199.   else if (runprog!=0 && fastmode==0){ runprogfun();saverunprogdata();}
  200.   else if (runprog!=0 && fastmode==1){ runprogfun();}
  201.   unsigned long currentmillis=millis();
  202.   if ((unsigned long)(currentmillis-lastmillis1)>=10000){lastmillis1=currentmillis;}}
  203.   if (runprog==0){stopall();}
  204.  
  205.   }
  206.  
  207. void getKey(){
  208.   // keypad read
  209.   key=16;
  210.   // Write :
  211.   Wire.beginTransmission(0x20);
  212.   Wire.write(0x13);      // port B data address
  213.   Wire.write(0b11111110);      // port B data
  214.   Wire.endTransmission();
  215.   // read
  216.   Wire.beginTransmission(0x20);
  217.   Wire.write(0x12);      // port A data address
  218.   Wire.endTransmission();
  219.   Wire.requestFrom(0x20,1); //request 1 byte
  220.   if(Wire.available()){
  221.     input=Wire.read();
  222.     if (input!=lastInput1){
  223.     if      ((input/16)==14){key=1;}
  224.     else if ((input/16)==13){key=2;}
  225.     else if ((input/16)==11){key=3;}
  226.     else if ((input/16)==7 ){key=10;}
  227.   }}
  228.   lastInput1=input;
  229.     // Write :
  230.   Wire.beginTransmission(0x20);
  231.   Wire.write(0x13);      // port B data address
  232.   Wire.write(0b11111101);      // port B data
  233.   Wire.endTransmission();
  234.   // read
  235.   Wire.beginTransmission(0x20);
  236.   Wire.write(0x12);      // port A data address
  237.   Wire.endTransmission();
  238.   Wire.requestFrom(0x20,1); //request 1 byte
  239.   if(Wire.available()){
  240.     input=Wire.read();
  241.     if (input!=lastInput2){
  242.     if      ((input/16)==14){key=4;}
  243.     else if ((input/16)==13){key=5;}
  244.     else if ((input/16)==11){key=6;}
  245.     else if ((input/16)==7 ){key=11;}}}
  246.     lastInput2=input;
  247.   // Write :
  248.   Wire.beginTransmission(0x20);
  249.   Wire.write(0x13);      // port B data address
  250.   Wire.write(0b11111011);      // port B data
  251.   Wire.endTransmission();
  252.   // read
  253.   Wire.beginTransmission(0x20);
  254.   Wire.write(0x12);      // port A data address
  255.   Wire.endTransmission();
  256.   Wire.requestFrom(0x20,1); //request 1 byte
  257.   if(Wire.available()){
  258.     input=Wire.read();
  259.     if (input!=lastInput3){
  260.     if      ((input/16)==14){key=7;}
  261.     else if ((input/16)==13){key=8;}
  262.     else if ((input/16)==11){key=9;}
  263.     else if ((input/16)==7 ){key=12;}}}
  264.     lastInput3=input;
  265.   // Write :
  266.   Wire.beginTransmission(0x20);
  267.   Wire.write(0x13);      // port B data address
  268.   Wire.write(0b11110111);      // port B data
  269.   Wire.endTransmission();
  270.   // read
  271.   Wire.beginTransmission(0x20);
  272.   Wire.write(0x12);      // port A data address
  273.   Wire.endTransmission();
  274.   Wire.requestFrom(0x20,1); //request 1 byte
  275.   if(Wire.available()){
  276.     input=Wire.read();
  277.     if (input!=lastInput4){
  278.     if      ((input/16)==14){key=14;}
  279.     else if ((input/16)==13){key=0;}
  280.     else if ((input/16)==11){key=15;}
  281.     else if ((input/16)==7 ){key=13;}}}
  282.     lastInput4=input;
  283. }
  284. void shift_serial_test (){
  285.    // reading serial
  286.   if(Serial.available()>0){
  287.     x=Serial.read();
  288.     if      (x=='a'){r=1;}
  289.     else if (x=='b'){r=2;}
  290.     else if (x=='c'){r=3;}
  291.     else {
  292.       if (r==1){bitWrite(dataout1,x-49,!bitRead(dataout1,x-49));r=0;}
  293.       if (r==2){bitWrite(dataout2,x-49,!bitRead(dataout2,x-49));r=0;}
  294.       if (r==3 && (x-49)<4){bitWrite(dataout3,x-49,!bitRead(dataout3,x-49));r=0;}
  295.     }
  296.  digitalWrite(latch,0);
  297.   shiftOut(data,clk,MSBFIRST,dataout3);
  298.   shiftOut(data,clk,MSBFIRST,dataout2);
  299.   shiftOut(data,clk,MSBFIRST,dataout1);
  300.   digitalWrite(latch,1);}
  301. }
  302. void valvecontrol (){
  303.  bitWrite(dataout1,0,!valvestatus[1]);
  304.  bitWrite(dataout1,1,!valvestatus[0]);
  305.  bitWrite(dataout2,0,!valvestatus[9]);
  306.  bitWrite(dataout2,1,!valvestatus[8]);
  307.  bitWrite(dataout2,2,!valvestatus[7]);
  308.  bitWrite(dataout2,3,!valvestatus[6]);
  309.  bitWrite(dataout2,4,!valvestatus[5]);
  310.  bitWrite(dataout2,5,!valvestatus[4]);
  311.  bitWrite(dataout2,6,!valvestatus[3]);
  312.  bitWrite(dataout2,7,!valvestatus[2]);
  313.   digitalWrite(latch,0);
  314.   shiftOut(data,clk,MSBFIRST,dataout3);
  315.   shiftOut(data,clk,MSBFIRST,dataout2);
  316.   shiftOut(data,clk,MSBFIRST,dataout1);
  317.   digitalWrite(latch,1);
  318.   }
  319. void RTC_LCD__test(){
  320.    lcd.setCursor(0,0);
  321.   Time nowTime = pcf.getTime();//get current time
  322.  
  323.   //print current time
  324.   lcd.print("date:");
  325.   lcd.print(nowTime.day);
  326.   RTCday=nowTime.day;
  327.   if (!(lastRTCday==RTCday)){day++;
  328.      if (day==7){day=0;}}
  329.   lastRTCday=RTCday;
  330.   lcd.print("/");
  331.   lcd.print(nowTime.month);
  332.   lcd.print("/");
  333.   lcd.print(nowTime.year);
  334.   lcd.setCursor(0,1);
  335.   lcd.print("time:");
  336.   lcd.print(nowTime.hour);
  337.   lcd.print(":");
  338.   lcd.print(nowTime.minute);
  339.   lcd.print(":");
  340.   lcd.print(nowTime.second);
  341.   lcd.setCursor(0,2);
  342.   lcd.print("day:");
  343.   lcd.print(dayStr [day]);
  344. }
  345. void setclock(){
  346.    //timer
  347.   pcf.init();//initialize the clock
  348.   pcf.stopClock();//stop the clock
  349.   //set time
  350.   pcf.setYear(setyear);//set year
  351.   pcf.setMonth(setmonth);//set month
  352.   pcf.setDay(setday);//set dat
  353.   pcf.setHour(sethour);//set hour
  354.   pcf.setMinut(setmin);//set minut
  355.   pcf.setSecond(0);//set second
  356.   pcf.startClock();//start the clock
  357.    Time nowTime = pcf.getTime();//get current time
  358. }
  359. void lcddisplay(){
  360.   // day timer
  361.   Time nowTime = pcf.getTime();//get current time
  362.   // day
  363.   RTCday=nowTime.day;
  364.   if (!(lastRTCday==RTCday)){day++; if (day==7){day=0;} saveday();}
  365.   lastRTCday=RTCday;
  366.  
  367.   if (pointer1==0){  // home
  368.   if (main_page_data==0){
  369.    lcd.setCursor(0,2);   lcd.print("valve  :");
  370.    lcd.setCursor(0,1);   lcd.print("program:");
  371.    lcd.setCursor(0,3);   lcd.print("PH:");
  372.    lcd.setCursor(9,3);   lcd.print("CE:");}
  373.     // sec
  374.   RTCsec=nowTime.second;
  375.   if (!(lastRTCsec==RTCsec)){
  376.   seccounter++; if (seccounter==5){timedis=!timedis;seccounter=0;}
  377.   lcd.setCursor(0,0);   lcd.print(dayStr [day]);
  378.   if (timedis==1){lcd.setCursor(9,0);   lcd.print(nowTime.day); lcd.print("/"); lcd.print(nowTime.month); lcd.print("/"); lcd.print("20");lcd.print(nowTime.year); }
  379.   else           {lcd.setCursor(9,0);   lcd.print(nowTime.hour);lcd.print(":");lcd.print(nowTime.minute);lcd.print(":");lcd.print(nowTime.second);lcd.print("  ");}
  380.   // current prog
  381.   lcd.setCursor(8,1);  
  382.   if (runprog>0){lcd.print(runprog);lcd.print(" ");}
  383.   else          {lcd.print("   ");}
  384.   if (progsta==0){lcd.print("running");lcd.print(" ");}
  385.   else           {lcd.print("paused ");lcd.print(" ");}
  386.   // current valve
  387.   lcd.setCursor(8,2);if (valverun>0){lcd.print(valverun);}lcd.print("  ");
  388.   // ph
  389.   lcd.setCursor(3,3);
  390.   if (valverun>0){
  391.   if (valvePH[valverun-1]>9){lcd.print(valvePH[valverun-1]/10);lcd.print(".");lcd.print(valvePH[valverun-1]%10);}
  392.   else                      {lcd.print(valvePH[valverun-1]);lcd.print(".0 ");}}
  393.   // CE
  394.   else {lcd.print("   ");}  
  395.   lcd.setCursor(12,3);  
  396.   if (valverun>0){
  397.   if (valveCE[valverun-1]>9){lcd.print(valveCE[valverun-1]/10);lcd.print(".");lcd.print(valveCE[valverun-1]%10);lcd.print(" ");}
  398.   else                     {lcd.print(valveCE[valverun-1]);lcd.print(".0 ");}}
  399.   else {lcd.print("   ");}
  400.   //T
  401.   if (progsta==0){
  402.   if (valvetimer[valverun-1]>0 && runprog>0){lcd.setCursor(15,2);lcd.print(valvetimer[valverun-1]-1);lcd.print(":");lcd.print(59-nowTime.second);lcd.print(" ");}
  403.   else                         {lcd.setCursor(15,2);lcd.print("    ");}}
  404.   }
  405.   main_page_data=1;
  406.   if (key==12){pointer1=1;pointer2=0; lcd.clear();main_page_data=0;}//setting
  407.   if (key==15){ lcd.clear();main_page_data=0;continueprog();}//start
  408.   if (key==14){ lcd.clear();main_page_data=0;stopprog();}//paused
  409.   lastRTCsec=RTCsec;}
  410.  
  411.   else if (pointer1==1){ //setting
  412.     if (main_page_data==0){
  413.   lcd.setCursor(0,0);   lcd.print("1_valve");
  414.   lcd.setCursor(10,0);   lcd.print("2_program");
  415.   lcd.setCursor(0,1);   lcd.print("3_clock");
  416.   lcd.setCursor(10,1);   lcd.print("4_test_val");
  417.   lcd.setCursor(0,2);   lcd.print("5_test_pro");
  418.   lcd.setCursor(10,2);   lcd.print("6_reset");
  419.   lcd.setCursor(0,3);   lcd.print("7_");
  420.   lcd.setCursor(10,3);   lcd.print("8_other");}
  421.    main_page_data=1;
  422.   if      (key==13){pointer1=0;pointer2=0;key=16 ;lcd.clear();save();main_page_data=0;} // home
  423.   else if (key==1 ){pointer1=2;pointer2=0;key=16 ; lcd.clear();main_page_data=0;} // valve setting
  424.   else if (key==2 ){pointer1=4;pointer2=0;key=16; lcd.clear();main_page_data=0;} // program setting
  425.   else if (key==3 ){pointer1=7;pointer2=0;key=16; lcd.clear();main_page_data=0;} // time setting
  426.   else if (key==4 ){pointer1=8;pointer2=0;key=16; lcd.clear();main_page_data=0;} // test valve
  427.   else if (key==5 ){pointer1=9;pointer2=0;key=16; lcd.clear();main_page_data=0;}// test prog
  428.   else if (key==6 ){pointer1=10;pointer2=0;key=16; lcd.clear();main_page_data=0;}// test prog
  429.    }
  430.  
  431.   else if (pointer1==2){  // valve setting page 1
  432.    // num  
  433.   lcd.setCursor(0,0); lcd.print("valve num");
  434.   if (pointer2==0){lcd.print(">");
  435.    if      (key==10 && valvenum<10){valvenum++;}
  436.    else if (key==11 && valvenum>1) {valvenum--;}
  437.     if (key<10){
  438.     if      (pointer3==0){number1=key;valvenum=number1;                                                pointer3=1;}
  439.     else if (pointer3==1){number2=key;valvenum=number1*10+number2; if (valvenum>11){valvenum=number2;} pointer3=0;}}}
  440.   else {lcd.print(":");}
  441.   lcd.print(" "); lcd.print(valvenum);lcd.print(" ");
  442.   //duration
  443.  lcd.setCursor(0,1); lcd.print("duration ");
  444.  if (pointer2==1){lcd.print(">");
  445.     if (key<10){
  446.               if      (pointer3==0){number1=key;valvedu[valvenum-1]=number1;                 pointer3=1;}
  447.               else if (pointer3==1){number2=key;valvedu[valvenum-1]=number1*10+number2;
  448.                                    if (valvedu[valvenum-1]>60){valvedu[valvenum-1]=number2;} pointer3=0;}}}
  449.  else {lcd.print(":");}
  450.  lcd.print(valvedu[valvenum-1]);lcd.print("min   ");
  451.  // ph
  452.  lcd.setCursor(0,2); lcd.print("PH");
  453.  if (pointer2==2){lcd.print(">");
  454.     if (key<10){
  455.        if      (pointer3==0){number1=key;valvePH[valvenum-1]=number1;                        pointer3=1;}
  456.        else if (pointer3==1){number2=key;valvePH[valvenum-1]=number1*10+number2;             pointer3=2;}
  457.        else if (pointer3==2){number3=key;valvePH[valvenum-1]=number1*100+number2*10+number3;
  458.        if (valvePH[valvenum-1]>140){valvePH[valvenum-1]=number2+number3*0.1;} pointer3=0;}}}
  459.  else {lcd.print(":");}
  460.  if (valvePH[valvenum-1]>9){lcd.print(" ");lcd.print(valvePH[valvenum-1]/10);lcd.print(".");lcd.print(valvePH[valvenum-1]%10);lcd.print("  ");}
  461.  else                      {lcd.print(" ");lcd.print(valvePH[valvenum-1]);lcd.print(".0 ");}
  462.  // CE
  463.  lcd.setCursor(10,2); lcd.print("CE");
  464.   if (pointer2==3){lcd.print(">");
  465.       if (key<10){
  466.         if      (pointer3==0){number1=key;valveCE[valvenum-1]=number1;                        pointer3=1;}
  467.         else if (pointer3==1){number2=key;valveCE[valvenum-1]=number1*10+number2;             pointer3=2;}
  468.         else if (pointer3==2){number3=key;valveCE[valvenum-1]=number1*100+number2*10+number3; pointer3=0;}}}
  469.   else {lcd.print(":");}
  470.  if (valveCE[valvenum-1]>9){lcd.print(" ");lcd.print(valveCE[valvenum-1]/10);lcd.print(".");lcd.print(valveCE[valvenum-1]%10);lcd.print("  ");}
  471.  else                      {lcd.print(" ");lcd.print(valveCE[valvenum-1]);lcd.print(".0 ");}
  472.  lcd.setCursor(0,3); lcd.print("p 1/2");
  473.  if (key==13){pointer1=0; lcd.clear();save();}  // home
  474.  else if (key==12){pointer1=1; lcd.clear();}  // settings
  475.  else if (key==15 && pointer2<4){pointer2++;pointer3=0;number1=0;number2=0;number3=0;} // next
  476.  else if (key==14 && pointer2>0){pointer2--;pointer3=0;number1=0;number2=0;number3=0;} // Beck
  477.  else if (key==14 && pointer2==0){pointer2=5;pointer3=0;number1=0;number2=0;number3=0;} // Beck to page 2
  478.  if (pointer2==4){pointer1=3;pointer2=1;pointer3=0;number1=0;number2=0;number3=0; lcd.clear(); key=16;}//go to page 2
  479.  if (pointer2==5){pointer1=3;pointer2=6;pointer3=0;number1=0;number2=0;number3=0; lcd.clear();if (valvenum>1){valvenum--;}}//back to page 2
  480.  }
  481.  
  482.  else if (pointer1==3){ // valve setting page 2
  483.     // num
  484.    lcd.setCursor(0,0); lcd.print("valve num");
  485.    if (pointer2==1){lcd.print(">");
  486.      if      (key==10 && valvenum<10){valvenum++;}
  487.      else if (key==11 && valvenum>1) {valvenum--;}
  488.       if (key<10){
  489.         if      (pointer3==0){number1=key;valvenum=number1;                                                pointer3=1;}
  490.         else if (pointer3==1){number2=key;valvenum=number1*10+number2; if (valvenum>11){valvenum=number2;} pointer3=0;}}}
  491.      else {lcd.print(":");}
  492.    lcd.print(" ");lcd.print(valvenum);lcd.print(" ");
  493.    //F1
  494.    lcd.setCursor(0,1); lcd.print("F1");
  495.      if (pointer2==2){lcd.setCursor(2,1);lcd.print(">");
  496.       if (key<10){
  497.        if      (pointer3==0){number1=key;fer1per[valvenum-1]=number1;                        pointer3=1;}
  498.        else if (pointer3==1){number2=key;fer1per[valvenum-1]=number1*10+number2;             pointer3=2;}
  499.        else if (pointer3==2){number3=key;fer1per[valvenum-1]=number1*100+number2*10+number3; pointer3=0;}}
  500.        if (fer1per[valvenum-1]>101){fer1per[valvenum-1]=number2*10+number3;}}
  501.      else {lcd.print(":");}
  502.      lcd.print(fer1per[valvenum-1]);lcd.print("  ");
  503.     //F2
  504.    lcd.setCursor(7,1); lcd.print("F2");
  505.    if (pointer2==3){lcd.setCursor(9,1);lcd.print(">");
  506.       if (key<10){
  507.        if      (pointer3==0){number1=key;fer2per[valvenum-1]=number1;                        pointer3=1;}
  508.        else if (pointer3==1){number2=key;fer2per[valvenum-1]=number1*10+number2;             pointer3=2;}
  509.        else if (pointer3==2){number3=key;fer2per[valvenum-1]=number1*100+number2*10+number3; pointer3=0;}}
  510.        if (fer2per[valvenum-1]>101){fer2per[valvenum-1]=number2*10+number3;}}
  511.    else {lcd.print(":");}
  512.    lcd.print(fer2per[valvenum-1]);lcd.print("  ");
  513.    //F3
  514.    lcd.setCursor(14,1);lcd.print("F3");
  515.      if (pointer2==4){lcd.setCursor(16,1);lcd.print(">");
  516.       if (key<10){
  517.        if      (pointer3==0){number1=key;fer3per[valvenum-1]=number1;                        pointer3=1;}
  518.        else if (pointer3==1){number2=key;fer3per[valvenum-1]=number1*10+number2;             pointer3=2;}
  519.        else if (pointer3==2){number3=key;fer3per[valvenum-1]=number1*100+number2*10+number3; pointer3=0;}}
  520.        if (fer3per[valvenum-1]>101){fer3per[valvenum-1]=number2*10+number3;}}
  521.      else {lcd.print(":");}
  522.      lcd.print(fer3per[valvenum-1]);lcd.print("  ");
  523.     //F4  
  524.    lcd.setCursor(0,2); lcd.print("F4");
  525.      if (pointer2==5){lcd.setCursor(2,2);lcd.print(">");
  526.       if (key<10){
  527.        if      (pointer3==0){number1=key;key=16;fer4per[valvenum-1]=number1;                        pointer3=1;}
  528.        else if (pointer3==1){number2=key;key=16;fer4per[valvenum-1]=number1*10+number2;             pointer3=2;}
  529.        else if (pointer3==2){number3=key;key=16;fer4per[valvenum-1]=number1*100+number2*10+number3; pointer3=0;}}
  530.        if (fer4per[valvenum-1]>101){fer4per[valvenum-1]=number2*10+number3;}}
  531.      else{lcd.print(":");}
  532.    lcd.print(fer4per[valvenum-1]);lcd.print("  ");
  533.     //F5
  534.    lcd.setCursor(7,2); lcd.print("F5");
  535.    if (pointer2==6){lcd.setCursor(9,2);lcd.print(">");
  536.      if (key<10){
  537.        if      (pointer3==0){number1=key;key=16;fer5per[valvenum-1]=number1;                        pointer3=1;}
  538.        else if (pointer3==1){number2=key;key=16;fer5per[valvenum-1]=number1*10+number2;             pointer3=2;}
  539.        else if (pointer3==2){number3=key;key=16;fer5per[valvenum-1]=number1*100+number2*10+number3; pointer3=0;}}
  540.        if (fer5per[valvenum-1]>101){fer5per[valvenum-1]=number2*10+number3;}}
  541.    else {lcd.print(":");}  
  542.    lcd.print(fer5per[valvenum-1]);lcd.print("  ");
  543.    
  544.    lcd.setCursor(0,3); lcd.print("p 2/2");
  545.    if      (key==15 && pointer2<7){pointer2++;pointer3=0;number1=0;number2=0;number3=0;} // next
  546.    else if (key==14 && pointer2>0){pointer2--;pointer3=0;number1=0;number2=0;number3=0;} // Beck
  547.    else if (key==13){pointer1=0; lcd.clear();save();main_page_data=0;}  // home
  548.    else if (key==12){pointer1=1; lcd.clear();main_page_data=0;}  // settings
  549.    if (pointer2==0){pointer1=2;pointer2=3;pointer3=0;number1=0;number2=0;number3=0;lcd.clear();main_page_data=0;}  // page1
  550.    if (pointer2==7){pointer1=2;pointer2=0;pointer3=0;number1=0;number2=0;number3=0;lcd.clear();valvenum++;main_page_data=0;}  //page 1
  551.     }
  552.    
  553.   else if (pointer1==4){ // program setting page 1
  554.    // num
  555.    lcd.setCursor(0,0); lcd.print("prog num: ");
  556.    if (pointer2==0){lcd.print(">");
  557.       if (key<10){
  558.         if      (pointer3==0){number1=key;prognum=number1;                                              pointer3=1;}
  559.         else if (pointer3==1){number2=key;prognum=number1*10+number2; if (prognum>25){prognum=number2;} pointer3=0;}}
  560.       if      (key==10 && prognum<25){prognum++;}
  561.       else if (key==11 && prognum>1) {prognum--;}}
  562.    else {lcd.print(":");}
  563.    lcd.print(" ");lcd.print(prognum);lcd.print(" ");
  564.    // ativation
  565.    lcd.setCursor(0,1); lcd.print("Activation");
  566.    if (pointer2==1){lcd.print(">");
  567.    if (key==10 || key==11){progact[prognum-1]=!progact[prognum-1];}}
  568.    else {lcd.print(":");}
  569.    if      (progact[prognum-1]==1){lcd.print(" on ");}
  570.    else if (progact[prognum-1]==0){lcd.print(" off ");}
  571.    //day
  572.    lcd.setCursor(0,2); lcd.print("days      ");
  573.     if (pointer2==2){lcd.print(">");
  574.        if      (key==1){progday1[prognum-1]=!progday1[prognum-1];}
  575.        else if (key==2){progday2[prognum-1]=!progday2[prognum-1];}
  576.        else if (key==3){progday3[prognum-1]=!progday3[prognum-1];}
  577.        else if (key==4){progday4[prognum-1]=!progday4[prognum-1];}
  578.        else if (key==5){progday5[prognum-1]=!progday5[prognum-1];}
  579.        else if (key==6){progday6[prognum-1]=!progday6[prognum-1];}
  580.        else if (key==7){progday7[prognum-1]=!progday7[prognum-1];}}
  581.     else {lcd.print(":");}
  582.    if (progday1[prognum-1]==1){lcd.print("S");} else {lcd.print(" ");}
  583.    if (progday2[prognum-1]==1){lcd.print("M");} else {lcd.print(" ");}
  584.    if (progday3[prognum-1]==1){lcd.print("T");} else {lcd.print(" ");}
  585.    if (progday4[prognum-1]==1){lcd.print("W");} else {lcd.print(" ");}
  586.    if (progday5[prognum-1]==1){lcd.print("T");} else {lcd.print(" ");}
  587.    if (progday6[prognum-1]==1){lcd.print("F");} else {lcd.print(" ");}
  588.    if (progday7[prognum-1]==1){lcd.print("S");} else {lcd.print(" ");}
  589.    
  590.    lcd.setCursor(0,3); lcd.print("p 1/3");
  591.    if      (key==15 && pointer2<7){pointer2++;pointer3=0;number1=0;number2=0;number3=0;} // next
  592.    else if (key==14 && pointer2>0){pointer2--;pointer3=0;number1=0;number2=0;number3=0;} // Beck
  593.    else if (key==14 && pointer2==0){pointer2=4;pointer3=0;number1=0;number2=0;number3=0;main_page_data=0;} // Beck to page 3
  594.    else if (key==13){pointer1=0; lcd.clear();save();}  // home
  595.    else if (key==12){pointer1=1; lcd.clear();main_page_data=0;}  // settings
  596.    if (pointer2==3){pointer1=5;pointer2=1; lcd.clear(); key=16;main_page_data=0;}//page 2
  597.    if (pointer2==4){pointer1=6;pointer2=3; lcd.clear(); key=16;if (prognum>1){prognum--;}main_page_data=0;}//page 3
  598.   }
  599.    
  600.   else if (pointer1==5){ // program setting page 2
  601.      // num
  602.    lcd.setCursor(0,0); lcd.print("prog num ");
  603.    if (pointer2==1){lcd.print(">");
  604.      if (key<10){
  605.         if      (pointer3==0){number1=key;prognum=number1;                                              pointer3=1;}
  606.         else if (pointer3==1){number2=key;prognum=number1*10+number2; if (prognum>25){prognum=number2;} pointer3=0;}}
  607.      if      (key==10 && prognum<25){prognum++;}
  608.      else if (key==11 && prognum>1) {prognum--;}}
  609.    else {lcd.print(":");}
  610.    lcd.print(prognum);lcd.print(" ");
  611.    // valve num
  612.    lcd.setCursor(0,1);lcd.print("Write valve num:");
  613.    if (pointer2==2){lcd.setCursor(15,1); lcd.print(">");
  614.      if (key<10){
  615.         if      (pointer3==0){ number1=key;progvalve=number1;                    pointer3=1;}
  616.         else if (pointer3==1){ number2=key;progvalve=number1*10+number2;                   }}
  617.      if (key==10){pointer3=0;number1=0;number2=0;number3=0;key=16;lcd.setCursor(16,1);lcd.print("  ");
  618.          if      (progvalve==1){progvalve1[prognum-1]=!progvalve1[prognum-1];}
  619.          else if (progvalve==2){progvalve2[prognum-1]=!progvalve2[prognum-1];}
  620.          else if (progvalve==3){progvalve3[prognum-1]=!progvalve3[prognum-1];}
  621.          else if (progvalve==4){progvalve4[prognum-1]=!progvalve4[prognum-1];}
  622.          else if (progvalve==5){progvalve5[prognum-1]=!progvalve5[prognum-1];}
  623.          else if (progvalve==6){progvalve6[prognum-1]=!progvalve6[prognum-1];}
  624.          else if (progvalve==7){progvalve7[prognum-1]=!progvalve7[prognum-1];}
  625.          else if (progvalve==8){progvalve8[prognum-1]=!progvalve8[prognum-1];}
  626.          else if (progvalve==9){progvalve9[prognum-1]=!progvalve9[prognum-1];}
  627.          else if (progvalve==10){progvalve10[prognum-1]=!progvalve10[prognum-1];}
  628.          progvalve=0;} // next                          
  629.    }
  630.    lcd.setCursor(16,1); if (pointer3>0){lcd.print(progvalve);}lcd.print(" ");
  631.    lcd.setCursor(6,3);lcd.print(" V:");
  632.    
  633.    if (progvalve1[prognum-1]==1){lcd.print("1");} else {lcd.print(" ");}
  634.    if (progvalve2[prognum-1]==1){lcd.print("2");} else {lcd.print(" ");}
  635.    if (progvalve3[prognum-1]==1){lcd.print("3");} else {lcd.print(" ");}
  636.    if (progvalve4[prognum-1]==1){lcd.print("4");} else {lcd.print(" ");}
  637.    if (progvalve5[prognum-1]==1){lcd.print("5");} else {lcd.print(" ");}
  638.    if (progvalve6[prognum-1]==1){lcd.print("6");} else {lcd.print(" ");}
  639.    if (progvalve7[prognum-1]==1){lcd.print("7");} else {lcd.print(" ");}
  640.    if (progvalve8[prognum-1]==1){lcd.print("8");} else {lcd.print(" ");}
  641.    if (progvalve9[prognum-1]==1){lcd.print("9");} else {lcd.print(" ");}
  642.    if (progvalve10[prognum-1]==1){lcd.print("10");} else {lcd.print("  ");}
  643.    
  644.    lcd.setCursor(0,3); lcd.print("p 2/3");
  645.    lcd.setCursor(0,2);lcd.print("Then pess UP ");
  646.    if      (key==15 && pointer2<3){pointer2++;pointer3=0;number1=0;number2=0;number3=0;} // next
  647.    else if (key==14 && pointer2>0){pointer2--;pointer3=0;number1=0;number2=0;number3=0;} // Beck
  648.    else if (key==13){pointer1=0; lcd.clear();save();main_page_data=0;}  // home
  649.    else if (key==12){pointer1=1; lcd.clear();main_page_data=0;}  // settings
  650.    if (pointer2==0){pointer1=4;pointer2=2;pointer3=0;number1=0;number2=0;number3=0;lcd.clear();main_page_data=0;}  // page 1
  651.    if (pointer2==3){pointer1=6;pointer2=1;pointer3=0;number1=0;number2=0;number3=0;lcd.clear();key=16;main_page_data=0;}  // page 3
  652.    }
  653.    
  654.    else if (pointer1==6){ // program setting page 3
  655.      // num
  656.      lcd.setCursor(0,0); lcd.print("prog num  ");
  657.      if (pointer2==1){lcd.print(">");
  658.        if (key<10){
  659.          if      (pointer3==0){number1=key;prognum=number1;                                              pointer3=1;}
  660.          else if (pointer3==1){number2=key;prognum=number1*10+number2; if (prognum>25){prognum=number2;} pointer3=0;}}
  661.        if      (key==10 && prognum<25){prognum++;}
  662.        else if (key==11 && prognum>1) {prognum--;}}
  663.      else {lcd.print(":");}
  664.      lcd.print(prognum);lcd.print(" ");
  665.      //hour
  666.      lcd.setCursor(0,1);lcd.print("start hour");
  667.      if (pointer2==2){lcd.print(">");
  668.            if (key<10){
  669.               if      (pointer3==0){number1=key;proghour[prognum-1]=number1;                                                          pointer3=1;}
  670.               else if (pointer3==1){number2=key;proghour[prognum-1]=number1*10+number2; if (proghour[prognum-1]>23){proghour[prognum-1]=number2;} pointer3=0;}}}
  671.      else {lcd.print(":");}
  672.      lcd.print(proghour[prognum-1]);lcd.print("h  ");
  673.      //min
  674.      lcd.setCursor(0,2);lcd.print("start min ");
  675.      if (pointer2==3){lcd.print(">");
  676.            if (key<10){
  677.               if      (pointer3==0){number1=key;progmin[prognum-1]=number1;                                                         pointer3=1;}
  678.               else if (pointer3==1){number2=key;progmin[prognum-1]=number1*10+number2; if (progmin[prognum-1]>59){progmin[prognum-1]=number2;} pointer3=0;}}}
  679.      else {lcd.print(":");}
  680.      lcd.print(progmin[prognum-1]);lcd.print("min  ");
  681.      lcd.setCursor(0,3); lcd.print("p 3/3");
  682.      if      (key==15 && pointer2<5){pointer2++;pointer3=0;number1=0;number2=0;number3=0;} // next
  683.      else if (key==14 && pointer2>0){pointer2--;pointer3=0;number1=0;number2=0;number3=0;} // Beck
  684.      else if (key==13){pointer1=0; lcd.clear();save();main_page_data=0;}  // home
  685.      else if (key==12){pointer1=1; lcd.clear();main_page_data=0;}  // settings
  686.      if (pointer2==0){pointer1=5;pointer2=2;pointer3=0;number1=0;number2=0;number3=0;lcd.clear();main_page_data=0;}            // page 2
  687.      if (pointer2==4){pointer1=4;pointer2=1;pointer3=0;number1=0;number2=0;number3=0;lcd.clear();prognum++;main_page_data=0;}  // page 1  
  688.    }  
  689.    
  690.   else if (pointer1==7){ // clock setting
  691.       // date
  692.       lcd.setCursor(0,0); lcd.print("data");
  693.        if (pointer2==0){lcd.print(">");
  694.        if (key<10){
  695.               if      (pointer3==0){number1=key;setday=number1;                                            pointer3=1;}
  696.               else if (pointer3==1){number2=key;setday=number1*10+number2; if (setday>31){setday=number2;} pointer3=0;}
  697.               setclock();}}
  698.        else {lcd.print(":");}
  699.       lcd.print("    ");
  700.       if (nowTime.day<10){lcd.print("0");lcd.print(nowTime.day);}
  701.       else               {lcd.print(nowTime.day);}
  702.       if (pointer2==1){lcd.print(">");
  703.         if (key<10){
  704.               if      (pointer3==0){number1=key;setmonth=number1;                                            pointer3=1;}
  705.               else if (pointer3==1){number2=key;setmonth=number1*10+number2; if (setmonth>12){setmonth=number2;} pointer3=0;}
  706.               setclock();}}
  707.       else {lcd.print("/");}
  708.       if (nowTime.month<10){lcd.print("0");lcd.print(nowTime.month); }
  709.       else                 {lcd.print(nowTime.month);}
  710.       if (pointer2==2){lcd.print(">");
  711.       if (key<10){
  712.               if      (pointer3==0){number1=key;setyear=number1;             pointer3=1;}
  713.               else if (pointer3==1){number2=key;setyear=number1*10+number2;  pointer3=0;}
  714.               setclock();}}
  715.       else {lcd.print("/");}
  716.       lcd.print("20");
  717.       if(nowTime.year>9){lcd.print(nowTime.year);}
  718.       else              {lcd.print("0");lcd.print(nowTime.year);}
  719.      // day
  720.       lcd.setCursor(0,1); lcd.print("day ");
  721.       if (pointer2==3){lcd.print(">"); if (key<8){day=key-1;}}
  722.       else {lcd.print(":");}
  723.       lcd.print("    "); lcd.print(dayStr[day]); lcd.print("    ");
  724.       // hour
  725.       lcd.setCursor(0,2); lcd.print("hour");
  726.        if (pointer2==4){lcd.print(">");
  727.        if (key<10){
  728.               if      (pointer3==0){number1=key;sethour=number1;                                              pointer3=1;}
  729.               else if (pointer3==1){number2=key;sethour=number1*10+number2; if (sethour>23){sethour=number2;} pointer3=0;}
  730.               setclock();}}
  731.        else{lcd.print(":");}
  732.        lcd.print("    ");lcd.print(nowTime.hour); lcd.print("h  ");
  733.       // min
  734.       lcd.setCursor(0,3); lcd.print("min ");
  735.           if (pointer2==5){lcd.print(">");
  736.           if (key<10){
  737.               if      (pointer3==0){number1=key;setmin=number1;                                            pointer3=1;}
  738.               else if (pointer3==1){number2=key;setmin=number1*10+number2; if (setmin>60){setmin=number2;} pointer3=0;}
  739.               setclock();}}
  740.           else {lcd.print(":");}
  741.           lcd.print("    ");lcd.print(nowTime.minute); lcd.print("min  ");
  742.       if      (key==15 && pointer2<5){pointer2++;number1=0;number2=0;} // next
  743.       else if (key==14 && pointer2>0){pointer2--;} // Beck
  744.       else if (key==13){pointer1=0; lcd.clear();main_page_data=0;saveday();}  // home
  745.       else if (key==12){pointer1=1; lcd.clear();main_page_data=0;}  // settings
  746.       }
  747.      
  748.   else if (pointer1==8){ // test valve
  749.     lcd.setCursor(0,0); lcd.print("choose valve num  ");
  750.     lcd.setCursor(0,1); lcd.print("then press next >");
  751.     if (testvalve>0){lcd.print(testvalve);}lcd.print("  ");
  752.     if (key<10){
  753.     if      (pointer3==0){number1=key;testvalve=number1;              pointer3=1;}
  754.     else if (pointer3==1){number2=key;testvalve=number1*10+number2;pointer3=0;}}
  755.     if (key==15){pointer3=0;valvestatus[testvalve-1]=!valvestatus[testvalve-1];testvalve=0;valvecontrol ();} // next
  756.    lcd.setCursor(0,2);
  757.    if (valvestatus[0]==1){lcd.print("1 ");} else {lcd.print("  ");}
  758.    if (valvestatus[1]==1){lcd.print("2 ");} else {lcd.print("  ");}
  759.    if (valvestatus[2]==1){lcd.print("3 ");} else {lcd.print("  ");}
  760.    if (valvestatus[3]==1){lcd.print("4 ");} else {lcd.print("  ");}
  761.    if (valvestatus[4]==1){lcd.print("5 ");} else {lcd.print("  ");}
  762.    if (valvestatus[5]==1){lcd.print("6 ");} else {lcd.print("  ");}
  763.    if (valvestatus[6]==1){lcd.print("7 ");} else {lcd.print("  ");}
  764.    if (valvestatus[7]==1){lcd.print("8 ");} else {lcd.print("  ");}
  765.    if (valvestatus[8]==1){lcd.print("9 ");} else {lcd.print("  ");}
  766.    if (valvestatus[9]==1){lcd.print("10");} else {lcd.print("  ");}
  767.     if (key==13){pointer1=0; lcd.clear();main_page_data=0;                      // home
  768.     for (int i=0;i<10;i++){valvestatus[i]=0;} valvecontrol ();main_page_data=0;}  
  769.     if (key==12){pointer1=1; lcd.clear();main_page_data=0;                      // settings
  770.     for (int i=0;i<10;i++){valvestatus[i]=0;} valvecontrol ();main_page_data=0;}  
  771.     }
  772.    
  773.    if (pointer1==9){ // test prog
  774.     lcd.setCursor(0,0); lcd.print("choose prog num  ");
  775.     lcd.setCursor(0,1); lcd.print("then press next >");
  776.     if (testprog>0){lcd.print(testprog);}lcd.print("  ");
  777.     lcd.setCursor(0,2); lcd.print("prog num:");
  778.     if (runprog>0){lcd.print(runprog);lcd.print(" "); lcd.setCursor(0,3); lcd.print("is running");}
  779.     if (key<10){
  780.     if      (pointer3==0){number1=key;testprog=number1;            pointer3=1;}
  781.     else if (pointer3==1){number2=key;testprog=number1*10+number2;pointer3=0;}}
  782.       if      (key==15){pointer3=0;runprog=testprog;testprog=0;} // next
  783.       else if (key==13){pointer1=0; lcd.clear();runprog=0;testprog=0;main_page_data=0;}  // home
  784.       else if (key==12){pointer1=1; lcd.clear();runprog=0;testprog=0;main_page_data=0;}  // settings
  785.   }
  786.    
  787.    else if (pointer1==10){ // reset
  788.     if (pointer2==0){
  789.        lcd.setCursor(0,0); lcd.print("1-reset valve seting");
  790.        lcd.setCursor(0,1); lcd.print("2-reset prog  seting");
  791.        lcd.setCursor(0,2); lcd.print("3-reset all   seting");
  792.        if      (key==1){pointer2=1;lcd.clear();}
  793.        else if (key==2){pointer2=2;lcd.clear();}
  794.        else if (key==3){pointer2=3;lcd.clear();}
  795.        }
  796.      if (pointer2==1){
  797.       lcd.setCursor(0,0); lcd.print("     valve reset    ");
  798.       lcd.setCursor(0,1); lcd.print("press next to reset ");
  799.       lcd.setCursor(0,2); lcd.print("press back to cancel");
  800.       if (key==15){pointer2=0;lcd.clear();valvereset();}//next
  801.       else if (key==14){pointer2=0; lcd.clear();}  //back
  802.      }
  803.      if (pointer2==2){
  804.       lcd.setCursor(0,0); lcd.print("     prog reset     ");
  805.       lcd.setCursor(0,1); lcd.print("press next to reset ");
  806.       lcd.setCursor(0,2); lcd.print("press back to cancel");
  807.       if (key==15){pointer2=0;lcd.clear();progreset();}//next
  808.       else if (key==14){pointer2=0; lcd.clear();}    //back
  809.      }
  810.      if (pointer2==3){
  811.       lcd.setCursor(0,0); lcd.print("     reset all     ");
  812.       lcd.setCursor(0,1); lcd.print("press next to reset");
  813.       lcd.setCursor(0,2); lcd.print("press back to cancel");
  814.       if (key==15){pointer2=0;lcd.clear();progreset(); valvereset();}//next
  815.       else if (key==14){pointer2=0; lcd.clear();}    // back
  816.      }
  817.       if (key==13){pointer1=0; lcd.clear();main_page_data=0;}  // home
  818.       else if (key==12){pointer1=1; lcd.clear();main_page_data=0;}// settings
  819.    }  
  820. key=16;  
  821. }
  822. void save(){
  823.   // valve
  824. lcd.setCursor(0,0);lcd.print("   saving data    ");
  825. for (int i=0;i<10;i++){
  826. lcd.setCursor(i,1);lcd.print(".");
  827. EEPROM.write(i,valvedu[i]);EEPROM.commit();
  828. EEPROM.write(i+10,fer1per[i]);EEPROM.commit();
  829. EEPROM.write(i+20,fer2per[i]);EEPROM.commit();
  830. EEPROM.write(i+30,fer3per[i]);EEPROM.commit();
  831. EEPROM.write(i+40,fer4per[i]);EEPROM.commit();
  832. EEPROM.write(i+50,fer5per[i]);EEPROM.commit();
  833. EEPROM.write(i+60,valvestatus[i]);EEPROM.commit();}
  834.   // prog
  835. for (int i=0;i<25;i++){
  836. lcd.setCursor(i+10,1);lcd.print(".");
  837. EEPROM.write(i+75,progact[i]);EEPROM.commit();
  838. EEPROM.write(i+100, progday1[i]);EEPROM.commit();
  839. EEPROM.write(i+125, progday2[i]);EEPROM.commit();
  840. EEPROM.write(i+150, progday3[i]);EEPROM.commit();
  841. EEPROM.write(i+175, progday4[i]);EEPROM.commit();
  842. EEPROM.write(i+200, progday5[i]);EEPROM.commit();
  843. EEPROM.write(i+225, progday6[i]);EEPROM.commit();
  844. EEPROM.write(i+250, progday7[i]);EEPROM.commit();
  845. EEPROM.write(i+275, proghour[i]);EEPROM.commit();
  846. EEPROM.write(i+300, progmin[i]);EEPROM.commit();
  847. EEPROM.write(i+325, progvalve1[i]);EEPROM.commit();
  848. EEPROM.write(i+350, progvalve2[i]);EEPROM.commit();
  849. EEPROM.write(i+375, progvalve3[i]);EEPROM.commit();
  850. EEPROM.write(i+400, progvalve4[i]);EEPROM.commit();
  851. EEPROM.write(i+425, progvalve5[i]);EEPROM.commit();
  852. EEPROM.write(i+450, progvalve6[i]);EEPROM.commit();
  853. EEPROM.write(i+475, progvalve7[i]);EEPROM.commit();
  854. EEPROM.write(i+500, progvalve8[i]);EEPROM.commit();
  855. EEPROM.write(i+525, progvalve9[i]);EEPROM.commit();
  856. EEPROM.write(i+550, progvalve10[i]);EEPROM.commit();}
  857. //PH EC
  858. for (int i=0,j=0;i<10;i++){
  859. EEPROM.write(i+600,valvePH[i]);EEPROM.commit();
  860. EEPROM.write(i+640,valveCE[i]);EEPROM.commit();}
  861. lcd.clear();
  862. }
  863. void load(){
  864.    // valve
  865.  lcd.setCursor(0,0);lcd.print("   loading data    ");
  866.  for (int i=0;i<10;i++) {
  867.  lcd.setCursor(i,1);lcd.print(".");
  868.  valvedu[i]=EEPROM.read(i);
  869.  fer1per[i]=EEPROM.read(i+10);
  870.  fer2per[i]=EEPROM.read(i+20);
  871.  fer3per[i]=EEPROM.read(i+30);
  872.  fer4per[i]=EEPROM.read(i+40);
  873.  fer5per[i]=EEPROM.read(i+50);
  874.  valvestatus[i]=EEPROM.read(i+60);}
  875.   // prog
  876.  for (int i=0;i<25;i++) {
  877.  lcd.setCursor(i+10,1);lcd.print(".");
  878.  progact[i]=EEPROM.read(i+75);
  879.  progday1[i]=EEPROM.read(i+100);
  880.  progday2[i]=EEPROM.read(i+125);
  881.  progday3[i]=EEPROM.read(i+150);
  882.  progday4[i]=EEPROM.read(i+175);
  883.  progday5[i]=EEPROM.read(i+200);
  884.  progday6[i]=EEPROM.read(i+225);
  885.  progday7[i]=EEPROM.read(i+250);
  886.  proghour[i]=EEPROM.read(i+275);
  887.  progmin[i]=EEPROM.read(i+300);
  888.  progvalve1[i]=EEPROM.read(i+325);
  889.  progvalve2[i]=EEPROM.read(i+350);
  890.  progvalve3[i]=EEPROM.read(i+375);
  891.  progvalve4[i]=EEPROM.read(i+400);
  892.  progvalve5[i]=EEPROM.read(i+425);
  893.  progvalve6[i]=EEPROM.read(i+450);
  894.  progvalve7[i]=EEPROM.read(i+475);
  895.  progvalve8[i]=EEPROM.read(i+500);
  896.  progvalve9[i]=EEPROM.read(i+525);
  897.  progvalve10[i]=EEPROM.read(i+550);}
  898.  //PH EC
  899.  for (int i=0,j=0;i<10;i++){
  900.   valvePH[i]=EEPROM.read(i+600);
  901.   valveCE[i]=EEPROM.read(i+640);}
  902.  lcd.clear();
  903. }
  904. void valvereset(){
  905.  // valves data
  906.  for (int i=0;i<10;i++){
  907.  valvedu[i]=0; valvePH[i]=0; valveCE[i]=0;fer1per[i]=0;
  908.  fer2per[i]=0; fer3per[i]=0;fer4per[i]=0; fer5per[i]=0;}
  909.  save();
  910. }
  911. void progreset(){
  912.  // program data
  913.  for (int i=0;i<25;i++){
  914.  progact[i]=0;progday1[i]=0;progday2[i]=0;progday3[i]=0;
  915.  progday4[i]=0;progday5[i]=0;progday6[i]=0;progday7[i]=0;
  916.  proghour[i]=0;progmin[i]=0;progvalve1[i]=0;progvalve2[i]=0;
  917.  progvalve3[i]=0;progvalve4[i]=0;progvalve5[i]=0;progvalve6[i]=0;
  918.  progvalve7[i]=0;progvalve8[i]=0;progvalve9[i]=0;progvalve10[i]=0;}
  919. save();
  920. }
  921. void checkprog(){
  922.   valverun=0;runprog=0;
  923.   // read time
  924.     Time nowTime = pcf.getTime();//get current time
  925.   // check active prog
  926.   for (int i=0;i<25;i++){ // i:prog num
  927.     if (progact[i]==1){
  928.       // check the day
  929.       if (day==0){// sunday
  930.         // ckeck if the day active and check hour and min
  931.           if (progday1[i]==1 && proghour[i]==nowTime.hour && progmin[i]==nowTime.minute){runprog=i+1;}}
  932.       else if (day==1){//monday
  933.         // ckeck if the day active and check hour and min
  934.           if (progday2[i]==1 && proghour[i]==nowTime.hour && progmin[i]==nowTime.minute){runprog=i+1;}}
  935.       else if (day==2){//tuesday
  936.          // ckeck if the day active and check hour and min
  937.           if (progday3[i]==1 && proghour[i]==nowTime.hour && progmin[i]==nowTime.minute){runprog=i+1;}}
  938.       else if (day==3){//wednesday
  939.         // ckeck if the day active and check hour and min
  940.           if (progday4[i]==1 && proghour[i]==nowTime.hour && progmin[i]==nowTime.minute){runprog=i+1;}}
  941.       else if (day==4){//theresday
  942.          // ckeck if the day active and check hour and min
  943.           if (progday5[i]==1 && proghour[i]==nowTime.hour && progmin[i]==nowTime.minute){runprog=i+1;}}
  944.       else if (day==5){//friday
  945.         // ckeck if the day active and check hour and min
  946.           if (progday6[i]==1 && proghour[i]==nowTime.hour && progmin[i]==nowTime.minute){runprog=i+1;}}
  947.       else if (day==6){//saturday
  948.         // ckeck if the day active and check hour and min
  949.           if (progday7[i]==1 && proghour[i]==nowTime.hour && progmin[i]==nowTime.minute){runprog=i+1;}}
  950.     }
  951.   }
  952. valverun=0;
  953. if (progvalve1[runprog-1]==1){valvetimer[0]=valvedu[0]+1;}  else {valvetimer[0]=0;}
  954. if (progvalve2[runprog-1]==1){valvetimer[1]=valvedu[1]+1;}  else {valvetimer[1]=0;}
  955. if (progvalve3[runprog-1]==1){valvetimer[2]=valvedu[2]+1;}  else {valvetimer[2]=0;}
  956. if (progvalve4[runprog-1]==1){valvetimer[3]=valvedu[3]+1;}  else {valvetimer[3]=0;}
  957. if (progvalve5[runprog-1]==1){valvetimer[4]=valvedu[4]+1;}  else {valvetimer[4]=0;}
  958. if (progvalve6[runprog-1]==1){valvetimer[5]=valvedu[5]+1;}  else {valvetimer[5]=0;}
  959. if (progvalve7[runprog-1]==1){valvetimer[6]=valvedu[6]+1;}  else {valvetimer[6]=0;}
  960. if (progvalve8[runprog-1]==1){valvetimer[7]=valvedu[7]+1;}  else {valvetimer[7]=0;}
  961. if (progvalve9[runprog-1]==1){valvetimer[8]=valvedu[8]+1;}  else {valvetimer[8]=0;}
  962. if (progvalve10[runprog-1]==1){valvetimer[9]=valvedu[9]+1;}  else {valvetimer[9]=0;}
  963. }
  964.  
  965. void runprogfun(){
  966.   // timer
  967.   Time nowTime = pcf.getTime();//get current time
  968.   // min
  969.   RTCmin=nowTime.minute;
  970.   if (!(lastRTCmin==RTCmin)){
  971.     Serial.print(runprog-1);Serial.print(runprog-1);
  972.     int totaltime=0;
  973.     if  (valvetimer[0]>0)                {valvestatus[0]=1; bitWrite(dataout1,1,!valvestatus[0]);shiftout();valvetimer[0]--;valverun=1;}
  974.     totaltime=totaltime+valvetimer[0];
  975.     if  (valvetimer[1]>0 && totaltime==0){valvestatus[1]=1; bitWrite(dataout1,0,!valvestatus[1]);shiftout();valvetimer[1]--;valverun=2;}
  976.     totaltime=totaltime+valvetimer[1];
  977.     if  (valvetimer[2]>0 && totaltime==0){valvestatus[2]=1; bitWrite(dataout2,7,!valvestatus[2]);shiftout();valvetimer[2]--;valverun=3;}
  978.     totaltime=totaltime+valvetimer[2];
  979.     if  (valvetimer[3]>0 && totaltime==0){valvestatus[3]=1; bitWrite(dataout2,6,!valvestatus[3]);shiftout();valvetimer[3]--;valverun=4;}
  980.     totaltime=totaltime+valvetimer[3];
  981.     if  (valvetimer[4]>0 && totaltime==0){valvestatus[4]=1; bitWrite(dataout2,5,!valvestatus[4]);shiftout();valvetimer[4]--;valverun=5;}
  982.     totaltime=totaltime+valvetimer[4];
  983.     if  (valvetimer[5]>0 && totaltime==0){valvestatus[5]=1; bitWrite(dataout2,4,!valvestatus[5]);shiftout();valvetimer[5]--;valverun=6;}
  984.     totaltime=totaltime+valvetimer[5];
  985.     if  (valvetimer[6]>0 && totaltime==0){valvestatus[6]=1; bitWrite(dataout2,3,!valvestatus[6]);shiftout();valvetimer[6]--;valverun=7;}
  986.     totaltime=totaltime+valvetimer[6];
  987.     if  (valvetimer[7]>0 && totaltime==0){valvestatus[7]=1; bitWrite(dataout2,2,!valvestatus[7]);shiftout();valvetimer[7]--;valverun=8;}
  988.     totaltime=totaltime+valvetimer[7];
  989.     if  (valvetimer[8]>0 && totaltime==0){valvestatus[8]=1; bitWrite(dataout2,1,!valvestatus[8]);shiftout();valvetimer[8]--;valverun=9;}
  990.     totaltime=totaltime+valvetimer[8];
  991.     if  (valvetimer[9]>0 && totaltime==0){valvestatus[9]=1; bitWrite(dataout2,0,!valvestatus[9]);shiftout();valvetimer[9]--;valverun=10;}
  992.     if (valvetimer[0]==0){valvestatus[0]=0; bitWrite(dataout1,1,!valvestatus[0]);shiftout();
  993.     if (valvetimer[1]==0){valvestatus[1]=0; bitWrite(dataout1,0,!valvestatus[1]);shiftout();
  994.     if (valvetimer[2]==0){valvestatus[2]=0; bitWrite(dataout2,7,!valvestatus[2]);shiftout();
  995.     if (valvetimer[3]==0){valvestatus[3]=0; bitWrite(dataout2,6,!valvestatus[3]);shiftout();
  996.     if (valvetimer[4]==0){valvestatus[4]=0; bitWrite(dataout2,5,!valvestatus[4]);shiftout();
  997.     if (valvetimer[5]==0){valvestatus[5]=0; bitWrite(dataout2,4,!valvestatus[5]);shiftout();
  998.     if (valvetimer[6]==0){valvestatus[6]=0; bitWrite(dataout2,3,!valvestatus[6]);shiftout();
  999.     if (valvetimer[7]==0){valvestatus[7]=0; bitWrite(dataout2,2,!valvestatus[7]);shiftout();
  1000.     if (valvetimer[8]==0){valvestatus[8]=0; bitWrite(dataout2,1,!valvestatus[8]);shiftout();
  1001.     if (valvetimer[9]==0){valvestatus[9]=0; bitWrite(dataout2,0,!valvestatus[9]);shiftout();valverun=0;runprog=0;}}}}}}}}}}
  1002.     }
  1003.     lastRTCmin=RTCmin;
  1004.    
  1005.     for (int i=0; i<10 ;i++){
  1006.       if (valvestatus[i]==1){
  1007.     unsigned long currentmillis=millis();
  1008.     if      (on_off_timer==0){
  1009.               if (fer1per[valverun-1]>on_timer){bitWrite(dataout1,7,0);}
  1010.               else                             {bitWrite(dataout1,7,1);}
  1011.               if (fer2per[valverun-1]>on_timer){bitWrite(dataout1,6,0);}
  1012.               else                             {bitWrite(dataout1,6,1);}
  1013.               if (fer3per[valverun-1]>on_timer){bitWrite(dataout1,5,0);}
  1014.               else                             {bitWrite(dataout1,5,1);}
  1015.               if (fer4per[valverun-1]>on_timer){bitWrite(dataout1,4,0);}
  1016.               else                             {bitWrite(dataout1,4,1);}
  1017.               if (fer5per[valverun-1]>on_timer){bitWrite(dataout1,3,0);}
  1018.               else                             {bitWrite(dataout1,3,1);}
  1019.             if ((unsigned long)(currentmillis-lastmillis)>=50){
  1020.               on_timer++;if (on_timer>100){on_timer=0;on_off_timer=1;}
  1021.               lastmillis=currentmillis;}
  1022.               shiftout();}
  1023.     else if (on_off_timer==1){
  1024.             bitWrite(dataout1,7,1);bitWrite(dataout1,5,1);bitWrite(dataout1,4,1);bitWrite(dataout1,6,1);shiftout();
  1025.             if ((unsigned long)(currentmillis-lastmillis)>=50){
  1026.               off_timer++;if (off_timer>100){off_timer=0;on_off_timer=0;}
  1027.               lastmillis=currentmillis;}}i=10;}}
  1028. }
  1029. void shiftout(){
  1030.      digitalWrite(latch,0);
  1031.     shiftOut(data,clk,MSBFIRST,dataout3);
  1032.     shiftOut(data,clk,MSBFIRST,dataout2);
  1033.     shiftOut(data,clk,MSBFIRST,dataout1);
  1034.     digitalWrite(latch,1);}
  1035.    
  1036. void saverunprogdata(){
  1037. Time nowTime = pcf.getTime();//get current time
  1038. progyear=nowTime.year;
  1039. progmonth=nowTime.month;
  1040. progday=nowTime.day;
  1041. progh=nowTime.hour;
  1042. progm=nowTime.minute;
  1043. for (int i=0;i<10;i++) {EEPROM.write(650+i,valvetimer[i]);EEPROM.commit();}
  1044. EEPROM.write(661,runprog);EEPROM.commit();
  1045. EEPROM.write(662,progyear);EEPROM.commit();
  1046. EEPROM.write(663,progmonth);EEPROM.commit();
  1047. EEPROM.write(664,progday);EEPROM.commit();
  1048. EEPROM.write(665,progh);EEPROM.commit();
  1049. EEPROM.write(666,progm);EEPROM.commit();
  1050. }
  1051.  
  1052. void loadrunprogdata(){
  1053.  lcd.setCursor(0,0);lcd.print("   loading data    ");
  1054.  for (int i=0;i<10;i++){valvetimer[i]= EEPROM.read(650+i);}
  1055.  runprog=EEPROM.read(661);
  1056.  progyear=EEPROM.read(662);
  1057.  progmonth=EEPROM.read(663);
  1058.  progday=EEPROM.read(664);
  1059.  progh=EEPROM.read(665);
  1060.  progm=EEPROM.read(666);
  1061.  Serial.print("runprog:"); Serial.print(runprog);
  1062.  Serial.print("date"); Serial.print(progday);Serial.print("/");
  1063.  Serial.print(progmonth);Serial.print("/");
  1064.  Serial.print(progyear);Serial.print("/");
  1065.  Serial.print("hour:"); Serial.print(progh);
  1066.  Serial.print("min"); Serial.print(progm);
  1067.  Serial.print("valve1du");Serial.println(valvetimer[0]);
  1068.  lcd.clear();}
  1069.  
  1070. void check_off_timer(){
  1071.     Time nowTime = pcf.getTime();//get current time
  1072.   if (progyear==nowTime.year &&  progmonth==nowTime.month && progday==nowTime.day){
  1073.     byte timediff=(nowTime.hour*60+nowTime.minute)-(progh*60+progm);
  1074.     if (timediff<180){fastmode=1;}
  1075.     else {fastmode=0;}
  1076.   Serial.println(timediff);}}
  1077.  
  1078. void fastcheck(){
  1079. valverun=0;runprog=0;
  1080.   // check active prog
  1081.   for (int i=0;i<25;i++){ // i:prog num
  1082.     if (progact[i]==1){
  1083.       // check the day
  1084.       if (day==0){// sunday
  1085.         // ckeck if the day active and check hour and min
  1086.           if (progday1[i]==1 && proghour[i]==progh && progmin[i]==progm){runprog=i+1;}}
  1087.       else if (day==1){//monday
  1088.         // ckeck if the day active and check hour and min
  1089.           if (progday2[i]==1 && proghour[i]==progh && progmin[i]==progm){runprog=i+1;}}
  1090.       else if (day==2){//tuesday
  1091.          // ckeck if the day active and check hour and min
  1092.           if (progday3[i]==1 && proghour[i]==progh && progmin[i]==progm){runprog=i+1;}}
  1093.       else if (day==3){//wednesday
  1094.         // ckeck if the day active and check hour and min
  1095.           if (progday4[i]==1 && proghour[i]==progh && progmin[i]==progm){runprog=i+1;}}
  1096.       else if (day==4){//theresday
  1097.          // ckeck if the day active and check hour and min
  1098.           if (progday5[i]==1 && proghour[i]==progh && progmin[i]==progm){runprog=i+1;}}
  1099.       else if (day==5){//friday
  1100.         // ckeck if the day active and check hour and min
  1101.           if (progday6[i]==1 && proghour[i]==progh && progmin[i]==progm){runprog=i+1;}}
  1102.       else if (day==6){//saturday
  1103.         // ckeck if the day active and check hour and min
  1104.           if (progday7[i]==1 && proghour[i]==progh && progmin[i]==progm){runprog=i+1;}}
  1105.     }
  1106.   }
  1107. valverun=0;
  1108. if (runprog!=0){
  1109. if (progvalve1[runprog-1]==1){valvetimer[0]=valvedu[0]+1;}  else {valvetimer[0]=0;}
  1110. if (progvalve2[runprog-1]==1){valvetimer[1]=valvedu[1]+1;}  else {valvetimer[1]=0;}
  1111. if (progvalve3[runprog-1]==1){valvetimer[2]=valvedu[2]+1;}  else {valvetimer[2]=0;}
  1112. if (progvalve4[runprog-1]==1){valvetimer[3]=valvedu[3]+1;}  else {valvetimer[3]=0;}
  1113. if (progvalve5[runprog-1]==1){valvetimer[4]=valvedu[4]+1;}  else {valvetimer[4]=0;}
  1114. if (progvalve6[runprog-1]==1){valvetimer[5]=valvedu[5]+1;}  else {valvetimer[5]=0;}
  1115. if (progvalve7[runprog-1]==1){valvetimer[6]=valvedu[6]+1;}  else {valvetimer[6]=0;}
  1116. if (progvalve8[runprog-1]==1){valvetimer[7]=valvedu[7]+1;}  else {valvetimer[7]=0;}
  1117. if (progvalve9[runprog-1]==1){valvetimer[8]=valvedu[8]+1;}  else {valvetimer[8]=0;}
  1118. if (progvalve10[runprog-1]==1){valvetimer[9]=valvedu[9]+1;}  else {valvetimer[9]=0;} }
  1119. progm++;if (progm>60){progm=0;progh++;}
  1120. check_off_timer();
  1121. }
  1122.  
  1123. void stopprog(){
  1124. progsta=1;
  1125. //stop all valve
  1126.     valvestatus[0]=0; bitWrite(dataout1,1,!valvestatus[0]);
  1127.     valvestatus[1]=0; bitWrite(dataout1,0,!valvestatus[1]);
  1128.     valvestatus[2]=0; bitWrite(dataout2,7,!valvestatus[2]);
  1129.     valvestatus[3]=0; bitWrite(dataout2,6,!valvestatus[3]);
  1130.     valvestatus[4]=0; bitWrite(dataout2,5,!valvestatus[4]);
  1131.     valvestatus[5]=0; bitWrite(dataout2,4,!valvestatus[5]);
  1132.     valvestatus[6]=0; bitWrite(dataout2,3,!valvestatus[6]);
  1133.     valvestatus[7]=0; bitWrite(dataout2,2,!valvestatus[7]);
  1134.     valvestatus[8]=0; bitWrite(dataout2,1,!valvestatus[8]);
  1135.     valvestatus[9]=0; bitWrite(dataout2,0,!valvestatus[9]);
  1136. //stop all fertilizers
  1137.    bitWrite(dataout1,7,1);
  1138.    bitWrite(dataout1,6,1);
  1139.    bitWrite(dataout1,5,1);
  1140.    bitWrite(dataout1,4,1);
  1141.    bitWrite(dataout1,3,1);
  1142.    shiftout();
  1143.    saverunprogdata();
  1144.    }
  1145.    
  1146. void continueprog(){
  1147. loadrunprogdata(); check_off_timer(); progsta=0;
  1148. }
  1149. void saveday (){
  1150. EEPROM.write(667,day);EEPROM.commit();
  1151. }
  1152. void loadday (){
  1153. day=EEPROM.read(667);
  1154. }
  1155. void stopall(){
  1156. //stop valve
  1157.     valvestatus[0]=0; bitWrite(dataout1,1,!valvestatus[0]);
  1158.     valvestatus[1]=0; bitWrite(dataout1,0,!valvestatus[1]);
  1159.     valvestatus[2]=0; bitWrite(dataout2,7,!valvestatus[2]);
  1160.     valvestatus[3]=0; bitWrite(dataout2,6,!valvestatus[3]);
  1161.     valvestatus[4]=0; bitWrite(dataout2,5,!valvestatus[4]);
  1162.     valvestatus[5]=0; bitWrite(dataout2,4,!valvestatus[5]);
  1163.     valvestatus[6]=0; bitWrite(dataout2,3,!valvestatus[6]);
  1164.     valvestatus[7]=0; bitWrite(dataout2,2,!valvestatus[7]);
  1165.     valvestatus[8]=0; bitWrite(dataout2,1,!valvestatus[8]);
  1166.     valvestatus[9]=0; bitWrite(dataout2,0,!valvestatus[9]);
  1167. //stop all fertilizers
  1168.    bitWrite(dataout1,7,1);
  1169.    bitWrite(dataout1,6,1);
  1170.    bitWrite(dataout1,5,1);
  1171.    bitWrite(dataout1,4,1);
  1172.    bitWrite(dataout1,3,1);
  1173.    shiftout();
  1174. }
RAW Paste Data