0

thats my flowchart for my code

    void loop()
{
  //-------------Fungsi Read sensor----------- 
  sensorAll();

  hasilec = (ppmcensor - inputec);
  ph = (phcensor - inputph);
  
//  hasilec = random(-200, 0) / 100.0;
//  ph = random(-200, 200) / 100.0;

//  ph = -180/100.0;
//  hasilec = -1.2;
  
  unsigned long now = millis();
  
  Serial.print("pH    ");
  Serial.print(ph);
  Serial.print("  ");
  Serial.print("EC ");
  Serial.print(hasilec);
  Serial.println("");
  Serial.print(ph);  Serial.print(" ");
  Serial.print(hasilec);   Serial.print(" ");
  Serial.println(" ");

//  delay (500000);
  
  fuzzy->setInput(2, hasilec);
  fuzzy->setInput(1, ph);  
  fuzzy->fuzzify();

  float pompa01 = fuzzy->defuzzify(1);//pHDOWN
  float pompa02 = fuzzy->defuzzify(2);//pHUP
  float pompa03 = fuzzy->defuzzify(3);//ABMIX
  
  Serial.println("Result= ");
  Serial.println("");
  Serial.print(" Pompa1 pHDOWN: ");
  Serial.println(pompa01);
  Serial.print(" pompa2 phUP  : ");
  Serial.println(pompa02);
  Serial.print(" pompa3 ABMIX : ");
  Serial.println(pompa03);
  Serial.println("");
  Serial.println("");
  Serial.println("");
  
  delay (2000);
  
  long int pompa1 = pompa01*1000;
  long int pompa2 = pompa02*1000;
  long int pompa3 = pompa03*1000;
  
  pump_periods[0] = pompa1; //PHdown
  pump_periods[1] = pompa2; //PHup
  pump_periods[2] = pompa3; //ABMIX
  
  for (int i = 0; i < jml_pump; i++) {
      if (now - pump_last_actuations[i] >= pump_periods[i]) {
          pump_states[i] = (pump_states[i] == LOW) ? HIGH : LOW;
          digitalWrite(pump_pins[i], pump_states[i]);
          pump_last_actuations[i] = now;
      }    
  }   
    
}

i now i cant use the delay and millis on the same time but how to get trick for thats code

9
  • You can use millis and still use a delay, but the delay will be processed always (meaning waiting for that time), and after the delay the millis will just be further in time with the same amount of time as the delay took. – Michel Keijzers Dec 18 '20 at 8:35
  • I also would expect the delay to be at the end of the loop function as it would be according to the flow chart (wait for 20 mins) and have a value of 1,200,000 instead of 2,000. – Michel Keijzers Dec 18 '20 at 8:47
  • What 1.200.000 for 1 pump ? – daffa faiz Dec 18 '20 at 12:08
  • In the flow chart I see 20 minutes, which is 20 minutes * 60 seconds/minute * 1000 ms/s = 1,200,000 ms. – Michel Keijzers Dec 18 '20 at 12:16
  • 2
    Does this answer your question? how to stop the relay after it is getting on and let the sensor get the result – ocrdu Dec 19 '20 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.