needd help with if function

hi, maybe it's stupid question :slight_smile: but why after the action laistOff when bout == HIGH wout dont get LOW.
can help me?

laistOn = (now.hour() >= 20 && now.minute() >= 21  || bout == HIGH);
laistOff = (now.hour() >= 20 && now.minute() >= 24 );

if (laistOn == true) {
  digitalWrite(wout, LOW);
}


 if ((laistOn != true) && (laistOff == true)) {
  digitalWrite(wout, HIGH);
 }

hard to tell from what little code was posted.

posted the entire code

[code]


//#define BLYNK_PRINT Serial


#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
char auth[] = "**************";
#define W5100_CS  10
#define SDCARD_CS 4
#define BLYNK_RED "#D3435C"
#define BLYNK_GREEN "#23C48E"


BlynkTimer timer;

#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7);
RTC_DS1307 rtc;

 int SR = (A9);
 int MR = (A8);
 int NR = (A10);
 int MM = (A11);

 boolean atidaryti = true;
 boolean uzdaryti = true;
 boolean laistOn = true;
 
 
 boolean laistOff = true;
 boolean outlasitOn = true;
 boolean outlaistOff = true;
  
 int inpu1 = 22;
 int inpu2 = 23;
 int inpu3 = 24;
 int inpu4 = 25;
 int inpu5 = 26;
 int inpu6 = 27;


                    int bdoor = 0;
                    int bin = 0;
                    int bout = 0;



const int reverse = 30;
const int door = 31;
const int window = 32;
const int laistymas = 33;
const int wout = 34;







char daysOfTheWeek[7][12] = {"Sekmad","Pirmad", "Antrad", "Trečiad", "Ketvirtad", "Penktad", "Šeštad"};


void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 100);
}

void setup () {
  Serial.begin(9600);
 
   pinMode(SDCARD_CS, OUTPUT); //blynk
  digitalWrite(SDCARD_CS, HIGH);
Blynk.begin(auth);
timer.setInterval(1000L, myTimerEvent);


    
    pinMode(reverse ,OUTPUT);
    pinMode(door ,OUTPUT);
    pinMode(window ,OUTPUT);
    pinMode(laistymas ,OUTPUT);
    pinMode(wout, OUTPUT);
    pinMode(inpu1,INPUT_PULLUP);
    pinMode(inpu2,INPUT_PULLUP);
    pinMode(inpu3,INPUT);
    pinMode(inpu4,INPUT);
    pinMode(inpu5, INPUT);
    pinMode(inpu6, INPUT);
   

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);

    
  }
  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2020, 04, 28, 21, 23, 0));   // <----------------------SET TIME AND DATE: YYYY,MM,DD,HH,MM,SS
  }
  delay(100);
  lcd.begin(16,2);

 
 rtc.adjust(DateTime(2020, 05, 5, 20, 20, 5)); // <----------------------SET TIME AND DATE: YYYY,MM,DD,HH,MM,SS   

}
       BLYNK_WRITE(V2)

                  {
                  bin = param.asInt();

                  if (param.asInt()== 1){
                  bin == HIGH;
                    } else { bin == LOW;
                   }

                  }
       BLYNK_WRITE(V3)

                  {
                  bout = param.asInt();

                  if (param.asInt()== 1){
                  bout == HIGH;
                    } else { bout == LOW;
                   }

                  }

                  BLYNK_WRITE(V4)

                  {
                  bdoor = param.asInt();

                  if (param.asInt()== 1){
                  bdoor == HIGH;
                    } else { bdoor == LOW;
                   }

                  }






void loop () {

    int dig = digitalRead(inpu1);
    int dig1 = digitalRead(inpu2);
    int dig2 = digitalRead(inpu3);
    int dig3 = digitalRead(inpu4);
    int dig4 = digitalRead(inpu5);
    int dig5 = digitalRead(inpu6);





Blynk.run();


if (dig==HIGH)                                               //jei durys atidarytos galinukas atidarytu duru (NC) 1 kont
{                                             
  Blynk.virtualWrite(V11,255);
  Blynk.setProperty(V11, "color", BLYNK_GREEN);
  Blynk.setProperty(V11, "label", "DURYS ATIDARYTOS");
}


if (dig1==HIGH)                                             //jei durys uzdarytos galinukas atidarytu duru (NO) 2 kont
  {
  Blynk.virtualWrite(V11,255);
  Blynk.setProperty(V11, "color", BLYNK_RED);
  Blynk.setProperty(V11, "label", "DURYS UŽDARYTOS");
 
}

if ((dig==LOW) && (dig1==LOW))                             //Jei nesuveikes JOKs galinukas (duru)  1kont - NO && 2kont NC
{
  Blynk.virtualWrite(V11,0);
  Blynk.setProperty(V11, "label", "VYKDOMA");
}









if (dig2==HIGH)

{ 
  Blynk.virtualWrite(V12,255);
  Blynk.setProperty(V12, "color", BLYNK_GREEN);
  Blynk.setProperty(V12, "label", "LANGAS ATIDARYTAS");
}


if (dig3==HIGH) {
  Blynk.virtualWrite(V12,255);
  Blynk.setProperty(V12, "color", BLYNK_RED);
  Blynk.setProperty(V12, "label", "LANGAS UŽDARYTAS");
 
}


if ((dig3==LOW) && (dig2==LOW))                             //Jei nesuveikes JOKs galinukas (lango)  1kont - NO && 2kont NC
{
  Blynk.virtualWrite(V12,0);
  Blynk.setProperty(V12, "label", "VYKDOMA");
}



if (dig4==LOW)

{ 
  Blynk.virtualWrite(V13,255);
  Blynk.setProperty(V13, "color", BLYNK_GREEN);
  Blynk.setProperty(V13, "label", "LAISTOMA VIDUJE");
}

else
{ (dig4==HIGH);
  Blynk.virtualWrite(V13,0);
  Blynk.setProperty(V13, "label", "VIDUJE NELAISTOMA");
}

if (dig5==LOW)

{ 
  Blynk.virtualWrite(V14,255);
  Blynk.setProperty(V14, "color", BLYNK_GREEN);
  Blynk.setProperty(V14, "label", "LAISTOMA LAUKE");
}

else
{ (dig5==HIGH);
  Blynk.virtualWrite(V14,0);
  Blynk.setProperty(V14, "label", "LAUKE NELAISTOMA");
}



if ( (dig == HIGH) && (dig2 ==  HIGH)) {
  digitalWrite(reverse, HIGH);

}
if ( (dig1 == HIGH) && (dig3 == HIGH)) { 

digitalWrite(reverse, LOW);
}










DateTime now = rtc.now();



    Serial.print(now.day(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.year(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    
    delay(200); //Print date and time every 1 sec
 
    

  
  lcd.setCursor(0, 0);
  lcd.print(now.year(), DEC);
  lcd.print('/');
  lcd.print(now.month(), DEC);
  lcd.print ('/');
  lcd.print(now.day(), DEC);

  lcd.setCursor(0, 1);
  lcd.print(now.hour(), DEC);
  lcd.print(':');
  lcd.print(now.minute(), DEC);
  lcd.print(':');
  lcd.print(now.second(), DEC);

  
  
  atidaryti = (now.hour() == 20 && now.minute() == 12 && now.second() == 5 || bdoor ==HIGH);
  uzdaryti = (now.hour() == 20 && now.minute() == 20 && now.second() == 30 );

    
if ((atidaryti == true)||(uzdaryti == true)) {         
  
 digitalWrite(door, LOW);
 digitalWrite(window, LOW);
 
}
 else {         
 
 digitalWrite(door, HIGH);
 digitalWrite(window, HIGH);

}


  laistOn = (now.hour() >= 20 && now.minute() >= 21  || bout == HIGH);
  laistOff = (now.hour() >= 20 && now.minute() >= 24 );

if (laistOn == true) {
  digitalWrite(wout, LOW);
}


 if ((laistOn != true) && (laistOff == true)) {
  digitalWrite(wout, HIGH);
 }
 
 



int NR = analogRead(A10);  // Agurkai vidus
int SR = analogRead(A9);   // Ridikai, salotos
int MR = analogRead(A8);   // Laukas
int MM = analogRead(A11);  // Vandens lygis




 SR = map(SR, 650, 340, 0,100); // Ridikai, salotos
 SR = constrain(SR, 0, 100);

  MR = map(MR, 650, 340, 0,100); // Laukas
 MR = constrain(MR, 0, 100);

 NR = map(NR, 650, 340, 0,100); // Agurkai vidus
 NR = constrain(NR, 0, 100); 

  MM = map(MM, 86, 36, 0,100); // Agurkai vidus
 
 
                                                              //int vala= analogRead(A9);
                                                                 //SR = map(vala, 340, 650, 100, 0);
lcd.setCursor(12,1);
lcd.println(SR);
lcd.setCursor(15,1);
lcd.println('%');
Blynk.virtualWrite(V20, SR);  // blynk Ridikai, salotos



Blynk.virtualWrite(V21, MR); // Laukas
Blynk.virtualWrite(V22, NR); // Agurkai vidus
Blynk.virtualWrite(V23, MM); // Vandens lygis















}

[/code]

Have you tried printing the values that you are testing with the if before the test ?
Are the values what you expect ?

Hello, I think that the value you are giving to the bool variable is unspecified. So the value of the variable is unspecified so neither of the two if() statements don't work. When declaring the variable, you should declare it like this:

bool variable = false;

Then it will work.

In the second if statement, you used this

if(wout != HIGH && wout == HIGH)

This won't be true because you use two opposite cases which should be possible at the same time. This if() statement won't work here.

What are these lines supposed to be doing?

                  bin == HIGH;

                  bout == HIGH;

                    } else { bout == LOW;

                  bdoor == HIGH;

                    } else { bdoor == LOW;

{ (dig4==HIGH);

{ (dig5==HIGH);

Hint:
single = assignment
double == comparison

Your code is littered with this apparent beginners coding error. I may not have found them all.

i'm a beginner if you can show me how it looks in code. Thank you :slight_smile:

You are using Blynk. The way you writing your BLYNK_WRITE() statements are wrong. Also one of the most important rules of Blynk is you must keep your void loop clean. Why are you using an rtc? Blynk has it's own rtc already all you have to do is add the widget and incorporate the code which is available on the sketck builder.
Your code

BLYNK_WRITE(V2)

                  {
                  bin = param.asInt();      // bin is assigned to V2

                  if (param.asInt()== 1){  // so if bin is 1 which means HIGH alraedy
                  bin == HIGH;         //this makes no sense as bin is HIGH alraedy
                    } else { bin == LOW;
                   }

                  }

What this should be is

BLYNK_WRITE(V2)
{
 bin = param.asInt();
 if (bin == 1)
  {
   Some code of what you want to happen when in is 1/HIGH
  }
  else
  {
   Some code of what you want to happen when bin is 0/LOW
  }
}

sinergija777:
i'm a beginner if you can show me how it looks in code. Thank you :slight_smile:

Yes, this is an assignment. It uses a single equals...

a = b;

After it executes variable a has been assigned the same value as variable b.

This is a comparison....

if (a == b) { ........ }

It checks if a equals b and if so executes the code in the if statement { ........ }.

This code is wrong/a mistake. It does nothing*...

a == b;

You have used the comparison operator (==) when you meant to use the assignment operator (=). I pointed out many lines in your posted code where you made this mistake.

This code is also almost certainly wrong, if you are ever tempted to write it...

if (a = b) { ........ }

It does not test if a equals b, because you have used the assignment operator (=) instead of compare (==). It does the assignment (copies b into a) then checks if a is non-zero.

Re-visiting this topic and in all honesty I seriously doubt this sketch worked. Looking at the void loop, the sketch will flood the Blynk server and as a result be thrown off. Apart from the basic C++ operations already mentioned above the OP should read through the documentation of Blynk to learn how it actually works.