Help need for counter status

Hello,

I want to count when the Releu=high and keep this value in memory

if (digitalRead(Plin) == LOW) // rezervor plin
      {
        Serial.println("Apa la maxim -- Cantitate = 1000 Litri ");
        digitalWrite(Releu, HIGH);  // pompa se opreste
        if (digitalRead(Releu) == HIGH)// contor rezervor plin
        {
                  count++; // Increase count by one
                Serial.print("Count: ");
                Serial.println(count);
delay(1000); 
        }
        digitalWrite(LedVerde, HIGH);  // led verde aprins
        digitalWrite(LedGalben, HIGH);  // led galben aprins
        digitalWrite(LedRosu, HIGH);    // led rosu aprins
      }
  
        else  // daca rezervorul nu e plin

void loop()

{

  if (digitalRead(Plin) == LOW) // rezervor plin
  {
    Serial.println("Apa la maxim -- Cantitate = 1000 Litri ");
    digitalWrite(Releu, HIGH);  // pompa se opreste
    if (digitalRead(Releu) == HIGH)// contor rezervor plin
    {
              Count++; // Increase count by one
              Serial.print("Count: ");
              Serial.println(Count);
              delay(1000); 
        }
    digitalWrite(LedVerde, HIGH);  // led verde aprins
    digitalWrite(LedGalben, HIGH);  // led galben aprins
    digitalWrite(LedRosu, HIGH);    // led rosu aprins
  }

    else  // daca rezervorul nu e plin
  
        if (digitalRead(Plin) == HIGH)
        {
          digitalWrite(LedVerde, HIGH); // led verde aprins
          delay(750);                  // timp aprins
          digitalWrite(LedVerde, LOW); // led verde stins
          delay(750);                  // timp stins
          digitalWrite(LedGalben, HIGH);  // led galben aprins
          digitalWrite(LedRosu, HIGH);    // led rosu aprins
        }

        
       else // daca  scazut nivelul sub jumatate
     
                if (digitalRead(Mijloc) == HIGH) 
                {
                  Serial.println("Apa sub jumatate= 500 Litri ");
                  digitalWrite(LedVerde, LOW);  // led verde stins
                  digitalWrite(LedGalben, HIGH); // led galben aprins
                  delay(450);                  // timp aprins
                  digitalWrite(LedGalben, LOW); // led galben stins
                  delay(450);                  // timp stins
                  digitalWrite(LedRosu, HIGH);    // led rosu aprins
                }

                
              else  // daca nivelul e sub minim
        
                        if (digitalRead(Gol) == HIGH) 
                        {
                          Serial.println("Rezervor gol");
                          digitalWrite(Releu, LOW);  // pompa porneste 
                          digitalWrite(LedVerde, LOW);  // led verde stins
                          digitalWrite(LedGalben, LOW);  // led galben stinss
                          digitalWrite(LedRosu, HIGH);    // led rosu aprins
                          delay(250);                  // timp aprins
                          digitalWrite(LedRosu, LOW);    // led rosu Stins
                          delay(250);                  // timp stins
                        }

}

Has your question got anything to do with the Arduino command line tools, which is the forum section that you posted in ?

Do you want to count how many times it is HIGH or how many times it becomes HIGH ? They are not the same thing at all

Thank you for your short answer; for me is important to see how many times it is High.

If you read the state of an input pin in loop() and count when it is HIGH then the state will be checked thousands of times per second and the count may be incremented thousands of times per second

If you read the state of an input pin in loop() and count when it becomes HIGH then the state will be checked thousands of times per second but the count will only be incremented once for every time the input becomes HIGH, such as when a button is pressed, for example

The first option is generally useless as the count is meaningless. Which one do you want to implement ?

yes , you are right, I need to see when becomes HIGH.

That seemed the likely option

Take a look at the StateChangeDetection example in the IDE

This is my change for counting, it is corect?

// definim variabile de numarare

int Count = 0;
int lastCount =0;


// Asta teoretic ruleaza o data pana se apasa reset:

void setup() {
  // initializam comunicatia seriala
  Serial.begin(9600);
  // pana la realizare voi folosi push butoane pentru test:

  pinMode(Plin, INPUT);
  pinMode(Mijloc, INPUT);
  pinMode(Gol, INPUT);
  pinMode(Releu, OUTPUT);
  pinMode(LedVerde, OUTPUT);
  pinMode(LedGalben, OUTPUT);
  pinMode(LedRosu, OUTPUT);
  digitalWrite(Plin, HIGH);
  digitalWrite(Mijloc, HIGH);
  digitalWrite(Gol, HIGH);
  digitalWrite(Releu, HIGH);   //RELEU APRINS
  digitalWrite(Releu, LOW);    //RELEU stins
  digitalWrite(LedVerde, LOW);   // led verde stins
  digitalWrite(LedGalben, LOW);  // led galben stins
  digitalWrite(LedRosu, LOW);    // led rosu stins
}

// Asta teoretic ruleaza mereu
void loop()

{

  if (digitalRead(Plin) == LOW) // rezervor plin
  {
    Serial.println("Apa la maxim -- Cantitate = 1000 Litri ");
    digitalWrite(Releu, HIGH);  // pompa se opreste
    Serial.println("Pompa umplere rezervor se opreste");
    if (Count != lastCount){  // contor rezervor plin     
      if (Releu == HIGH){ 
      Count++; // Increase count by one
      Serial.print("Count: ");
      Serial.print("Time:  ");
      Serial.println(Count);
      delay(1000);
    }
    digitalWrite(LedVerde, HIGH);  // led verde aprins
    digitalWrite(LedGalben, HIGH);  // led galben aprins
    digitalWrite(LedRosu, HIGH);    // led rosu aprins
  }

  else

Hello
please post your sketch well formated and in code tags.

Why are you testing whether the value of Count has changed ? You should be testing whether the state of the input pin has changed

This is a good question, so I remove testing.

Post your latest code here in a new post and please use code tags when you do

See How to get the best out of this forum

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.