munther_abdellatif

set_clock_20_6_2020

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