munther_abdellatif

checkprog_checkvalve22_06_2020

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