#include #include #include LiquidCrystal_I2C lcd(0x27, 16, 2); int pompa=10;//deklaracje int ele1=2; int ele2=4; int ele3=7; int ele4=8; int S = 10; // count seconds int M = 0; // count minutes int S2 = 15; int M2 = 0; int S3 = 0; int M3 = 0; int redPin = 3; // led int greenPin = 5; // led int bluePin = 6; // led long h = 3600000; // 3600000 milliseconds in an hour long m = 60000; // 60000 milliseconds in a minute long s= 1000; // 1000 milliseconds in a second long czas = 0; unsigned long zapamietany_czas = 0; unsigned long aktualny_czas =0; const unsigned long Interwal = 1000 ; unsigned long previousTime = 0; const byte ROWS = 4; //four rows const byte COLS = 3; //three columns char keys[ROWS][COLS] = { {'1','2','3'}, {'4','5','6'}, }; byte rowPins[ROWS] = {11, 12}; //connect to the row pinouts of the keypad byte colPins[COLS] = {13,A3,A2}; //connect to the column pinouts of the keypad Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); void stoper ( int Min, int Sec){ if(Min==0 && Sec==0){ M=0; S=1;} lcd.setCursor(2,1); lcd.print(":"); unsigned long currentTime = millis(); if (currentTime - previousTime >= Interwal){ S--; previousTime = currentTime; if(S<0) { M--; S=59; } if(M>9) { lcd.setCursor(0,1); lcd.print(M); } else { lcd.setCursor(0,1); lcd.print("0"); lcd.setCursor(1,1); lcd.print(M); lcd.setCursor(2,1); lcd.print(":"); } if(S>9) { lcd.setCursor(3,1); lcd.print(S); } else { lcd.setCursor(3,1); lcd.print("0"); lcd.setCursor(4,1); lcd.print(S); } if (M == 0 && S == 0){ M = Min; S = Sec; } }} void stoper2 ( int Min2, int Sec2){ if(Min2==0 && Sec2==0){ M2=0; S2=1;} lcd.setCursor(2,1); lcd.print(":"); unsigned long currentTime = millis(); if (currentTime - previousTime >= Interwal){ S2--; previousTime = currentTime; if(S2<0) { M2--; S2=59; } if(M2>9) { lcd.setCursor(0,1); lcd.print(M2); } else { lcd.setCursor(0,1); lcd.print("0"); lcd.setCursor(1,1); lcd.print(M2); lcd.setCursor(2,1); lcd.print(":"); } if(S2>9) { lcd.setCursor(3,1); lcd.print(S2); } else { lcd.setCursor(3,1); lcd.print("0"); lcd.setCursor(4,1); lcd.print(S2); } if (M2 == 0 && S2 == 0){ M2 = Min2; S2 = Sec2; } }} void stoper3 ( int Min3, int Sec3){ if(Min3==0 && Sec3==0){ M3=0; S3=1;} lcd.setCursor(2,1); lcd.print(":"); unsigned long currentTime = millis(); if (currentTime - previousTime >= Interwal){ S3--; previousTime = currentTime; if(S3<0) { M3--; S3=59; } if(M3>9) { lcd.setCursor(0,1); lcd.print(M3); } else { lcd.setCursor(0,1); lcd.print("0"); lcd.setCursor(1,1); lcd.print(M3); lcd.setCursor(2,1); lcd.print(":"); } if(S3>9) { lcd.setCursor(3,1); lcd.print(S3); } else { lcd.setCursor(3,1); lcd.print("0"); lcd.setCursor(4,1); lcd.print(S3); } if (M3 == 0 && S3 == 0){ M3 = Min3; S3 = Sec3; } }} void setColor(int red, int green, int blue) { #ifdef COMMON_ANODE red = 255 - red; green = 255 - green; blue = 255 - blue; #endif analogWrite(redPin, red); analogWrite(greenPin, green); analogWrite(bluePin, blue); } void setup() { pinMode(2, OUTPUT); //elektro zawór 1 pinMode(4, OUTPUT); //elektro zawór 2 pinMode(7, OUTPUT); //elektro zawór 3 pinMode(8, OUTPUT); //elektro zawór 4 pinMode(10, OUTPUT); //pompa pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); digitalWrite(pompa, HIGH); //Wyłączenie wszystkiego digitalWrite(ele1, HIGH); digitalWrite(ele2, HIGH); digitalWrite(ele3, HIGH); digitalWrite(ele4, HIGH); lcd.begin(); lcd.backlight(); lcd.print("Czas:"); } void loop() { aktualny_czas=millis(); char key = keypad.getKey(); if(!key){ zapamietany_czas=millis(); while(aktualny_czas-zapamietany_czas<= 100*s){ aktualny_czas=millis(); if(aktualny_czas-zapamietany_czas >= 0*s && aktualny_czas-zapamietany_czas < 15*s ) { digitalWrite(pompa, HIGH); digitalWrite(ele1, HIGH); digitalWrite(ele2, HIGH); digitalWrite(ele3, HIGH); digitalWrite(ele4, HIGH); setColor(0, 255, 0); stoper2(0,15);} if(aktualny_czas-zapamietany_czas >= 15*s && aktualny_czas-zapamietany_czas < 25*s ) { digitalWrite(pompa, LOW); digitalWrite(ele1, LOW); setColor(0, 0, 255); stoper(0,10);} if(aktualny_czas-zapamietany_czas >= 25*s && aktualny_czas-zapamietany_czas < 40*s){ digitalWrite(pompa, HIGH); digitalWrite(ele1, HIGH); setColor(0, 255, 0); stoper2(0,15);} if(aktualny_czas-zapamietany_czas >= 40*s && aktualny_czas-zapamietany_czas < 50*s){ digitalWrite(pompa, LOW); digitalWrite(ele2, LOW); setColor(0, 0, 255); stoper(0,10);} if(aktualny_czas-zapamietany_czas >= 50*s && aktualny_czas-zapamietany_czas < 65*s){ digitalWrite(pompa, HIGH); digitalWrite(ele2, HIGH); setColor(0, 255, 0); stoper2(0,15);} if(aktualny_czas-zapamietany_czas >= 65*s && aktualny_czas-zapamietany_czas < 75*s){ digitalWrite(pompa, LOW); digitalWrite(ele3, LOW); setColor(0, 0, 255); stoper(0,10);} if(aktualny_czas-zapamietany_czas >= 75*s && aktualny_czas-zapamietany_czas < 90*s){ digitalWrite(pompa, HIGH); digitalWrite(ele3, HIGH); setColor(0, 255, 0); stoper2(0,15);} if(aktualny_czas-zapamietany_czas >= 90*s && aktualny_czas-zapamietany_czas < 100*s){ digitalWrite(pompa, LOW); digitalWrite(ele4, LOW); setColor(0, 0, 255); stoper(0,10); } key = keypad.getKey(); if(key=='1' || key=='2' || key=='3' || key=='4' || key=='5' || key=='6'){ break; stoper(0,0);} } zapamietany_czas=aktualny_czas; } if(key == '1'){ while(1){ digitalWrite(pompa, LOW); digitalWrite(ele1, LOW); setColor(255, 255, 0); key = keypad.getKey(); if( key=='6'){ digitalWrite(pompa, HIGH); digitalWrite(ele1, HIGH); digitalWrite(ele2, HIGH); digitalWrite(ele3, HIGH); digitalWrite(ele4, HIGH); setColor(0, 255, 0); stoper2(0,15); break;} } } if(key == '2'){ while(1){ digitalWrite(pompa, LOW); digitalWrite(ele2, LOW); setColor(255, 255, 0); key = keypad.getKey(); if( key=='6'){ digitalWrite(pompa, HIGH); digitalWrite(ele1, HIGH); digitalWrite(ele2, HIGH); digitalWrite(ele3, HIGH); digitalWrite(ele4, HIGH); setColor(0, 255, 0); stoper(0,0); break;} } } if(key == '3'){ while(1){ digitalWrite(pompa, LOW); digitalWrite(ele3, LOW); setColor(255, 255, 0); key = keypad.getKey(); if( key=='6'){ digitalWrite(pompa, HIGH); digitalWrite(ele1, HIGH); digitalWrite(ele2, HIGH); digitalWrite(ele3, HIGH); digitalWrite(ele4, HIGH); setColor(0, 255, 0); stoper(0,0); break;} } } if(key == '4'){ while(1){ digitalWrite(pompa, LOW); digitalWrite(ele4, LOW); setColor(255, 255, 0); key = keypad.getKey(); if( key=='6'){ digitalWrite(pompa, HIGH); digitalWrite(ele1, HIGH); digitalWrite(ele2, HIGH); digitalWrite(ele3, HIGH); digitalWrite(ele4, HIGH); setColor(0, 255, 0); stoper(0,0); break;} } } if(key == '5'){ while(1){ setColor(255,0, 0); stoper3(0,0); key = keypad.getKey(); if( key=='6'){ digitalWrite(pompa, HIGH); digitalWrite(ele1, HIGH); digitalWrite(ele2, HIGH); digitalWrite(ele3, HIGH); digitalWrite(ele4, HIGH); setColor(0, 255, 0); stoper3(0,0); break;} } } }