-1
#include <Wire.h>
#include "DFRobot_LCD.h"

DFRobot_LCD lcd(16, 2); //16 characters and 2 lines of show

#define PH_PIN 25 
float voltage,phvalue,temperature = 25;

float acidVoltage =  (1990); //buffer solution at 4.o 
float neutralVoltage = (1389);   //buffer solution at 7.o 

void breath(unsigned char color){
     for(int i=0; i<255; i++){
        lcd.setPWM(color, i);
        delay(5);
    }

    delay(500);
    for(int i=254; i>=0; i--){
        lcd.setPWM(color, i);
        delay(1000);
    }

    delay (300) ;
}

void setup()
{
    Serial.begin(11520);
    // LCD Begin //
   lcd.init();
   lcd.setCursor(4,0);
   lcd.print("Welcome");
   delay(3000);
   lcd.clear();

   lcd.setCursor(3,0);
   lcd.print("Reading PH");
    delay(5000);
   lcd.clear();

  lcd.setCursor(3,0);
   lcd.print("Please Wait");
   delay(5000);
   lcd.clear();
}

void loop(){
  void loop1();
  void loop2();
  void loop3();
}

**void loop1(){
  static unsigned long timepoint = millis();
  if(millis()-timepoint>1000U){
    
    timepoint = millis();
    // timepoint = read temperature 

    voltage = analogRead (PH_PIN)/4095.0*3300; 

    float slope = (7.0-4.0)/((neutralVoltage-1500)/30 - (acidVoltage-1500)/3.0);
    float intercept = 7.0 - slope*(neutralVoltage-1500)/3.0;

    phvalue = slope*(voltage-1500)/3.0 + intercept;   // y=k*x + b [formula]
    
  if (phvalue > 3.8 && phvalue < 4.1){
    Serial.print("Voltage:");
    Serial.print(voltage,1);
    Serial.print("PH:");
    Serial.println(phvalue,2);

    //LCD setting 16x2
    lcd.setCursor(0,0);
    lcd.print("PH :     ");
    lcd.print(phvalue,2);

    lcd.setCursor(0,1);
    lcd.print("Volt :     ");
    lcd.print(voltage/1000,2);
    }
    else {
    Serial.begin(11520);
  // LCD Begin //
    lcd.init();
    lcd.setCursor(4,0);
    lcd.print("Dosing Required");
    delay(2000);
    lcd.clear();
  }
  }

  }


void loop2(){
  static unsigned long timepoint = millis();
  if(millis()-timepoint>1000U){
    
    timepoint = millis();
    // timepoint = read temperature 

    voltage = analogRead (PH_PIN)/4095.0*3300; 

    float slope = (7.0-4.0)/((neutralVoltage-1500)/30 - (acidVoltage-1500)/3.0);
    float intercept = 7.0 - slope*(neutralVoltage-1500)/3.0;

    phvalue = slope*(voltage-1500)/3.0 + intercept;   // y=k*x + b [formula]
    
  if (phvalue > 6.8 && phvalue < 7.1){
    Serial.print("Voltage:");
    Serial.print(voltage,1);
    Serial.print("PH:");
    Serial.println(phvalue,2);

    //LCD setting 16x2
    lcd.setCursor(0,0);
    lcd.print("PH :     ");
    lcd.print(phvalue,2);

    lcd.setCursor(0,1);
    lcd.print("Volt :     ");
    lcd.print(voltage/1000,2);
    }
    else {
    Serial.begin(11520);
  // LCD Begin //
    lcd.init();
    lcd.setCursor(4,0);
    lcd.print("Dosing Required");
    delay(2000);
    lcd.clear();
  }
}
}

void loop3 (){
  static unsigned long timepoint = millis();
  if(millis()-timepoint>1000U){
    
    timepoint = millis();
    // timepoint = read temperature 

    voltage = analogRead (PH_PIN)/4095.0*3300; 

    float slope = (7.0-4.0)/((neutralVoltage-1500)/30 - (acidVoltage-1500)/3.0);
    float intercept = 7.0 - slope*(neutralVoltage-1500)/3.0;

    phvalue = slope*(voltage-1500)/3.0 + intercept;   // y=k*x + b [formula]
    
  if (phvalue > 9.8 && phvalue < 10.1){
    Serial.print("Voltage:");
    Serial.print(voltage,1);
    Serial.print("PH:");
    Serial.println(phvalue,2);

    //LCD setting 16x2
    lcd.setCursor(0,0);
    lcd.print("PH :     ");
    lcd.print(phvalue,2);

    lcd.setCursor(0,1);
    lcd.print("Volt :     ");
    lcd.print(voltage/1000,2);
    }
    else {
    Serial.begin(11520);
  // LCD Begin //
    lcd.init();
    lcd.setCursor(4,0);
    lcd.print("Dosing Required");
    delay(2000);
    lcd.clear();
  }
  }
  }**
 

I am programming a ph sensor with lcd, i have tried multiple option as i needed to do alot of else/if statementdue to the requirement, however in the bolded section of my code the lcd is not showing i am unsure what i am doing wrong, is it due to a simple error?

i need to seperate out my if statement as i need it do this acion below

if phvalue range of (3.8-4.1) it will show ph : 3.8 volt: 1.68

else [ if out of range ] it will show Dosing Required

this will repeat 3 times with different value

romkey
  • 6,218
  • 3
  • 16
  • 12
  • Please do not tag spam. This has nothing to do with the ESP8266; don't use ESP8266 tags on it. – romkey Dec 06 '22 at 18:34

1 Answers1

1
static unsigned long timepoint = millis();
if(millis()-timepoint>1000U)

Like in your last post you have a simple logical error. You save a timestamp and instantly check if one second has passed since then. This condition will never be true. That's why nothing is happening.

Piglet
  • 27,501
  • 3
  • 20
  • 43