Boolean Logic with Virtual Pins

Does anyone have a bit of sample code working with multiple virtual pins in boolean logic arguments? I am trying to require two logical High’s in order to turn on a relay but can’t seem to get this right. All comments appreciated.

Thanks,
R

  int enableState = LOW;
  int timerState = LOW;
  
}

BLYNK_WRITE(1)
{
  enableState = (param.asInt());
}

BLYNK_WRITE(2)
{
  timerState = (param.asInt());
} 
  
{
  if (enableState && timerState == HIGH){
    digitalWrite(2, LOW);
    } else  {
    digitalWrite(2, HIGH);  
}

When using virtual pins, change HiGH and LOW to 1 and 0 respectively.

Also, too many parentheses here:

enableState = (param.asInt());

Change to:
enableState = param.asInt();

Also this line is a bit counter intuitive,

You might like to try

if( (enableState == HIGH) && (timerState == HIGH) ){

(yes it has to many parentheses, but they help show how things are grouped).

Also, you can get away with

if( enableState && timerState ){
1 Like

Nick, Pavel,

Still wrestling with this,… I have followed your advice and the syntax is correct I believe. I have placed the IF statement in ‘void loop’ and get the following errors on the serial monitor;

[0] Blynk v0.3.0
[0] Getting IP...
[1870] My IP: 192.168.1.209
[5001] Connecting to cloud.blynk.cc:8442
[5233] Ready (ping: 60ms).
[5257] Trouble detected: http://tiny.cc/blynk-bug#flood
[10234] Connecting to cloud.blynk.cc:8442
[10472] Ready (ping: 64ms).
[10492] Trouble detected: http://tiny.cc/blynk-bug#flood
[15473] Connecting to cloud.blynk.cc:8442
[15710] Ready (ping: 63ms).
[15731] Trouble detected: http://tiny.cc/blynk-bug#flood

Where is the proper place for this code when using Blynk?

#define BLYNK_PRINT Serial // Enables Serial Monitor
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h> // This part is for Ethernet stuff

char auth[] = "3fa959f4f931489ab215d889ea92e369"; // Put your Auth Token here. (see Step 3 above)

  int enableZone1 = 0;
  int timerZone1 = 0;
  int manualZone1 = 0;


void setup()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
  Blynk.begin(auth);  // Here your Arduino connects to the Blynk Cloud.
  
  //  Set all Arduino outputs to HIGH in respect to Relay Board
  
  pinMode(2, OUTPUT); // Zone 1
  digitalWrite(2, HIGH);


  
  pinMode(3, OUTPUT);
  digitalWrite(3, HIGH);
  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);
  pinMode(5, OUTPUT);
  digitalWrite(5, HIGH);
  pinMode(6, OUTPUT);
  digitalWrite(6, HIGH);
  pinMode(7, OUTPUT);
  digitalWrite(7, HIGH);
  pinMode(8, OUTPUT);
  digitalWrite(8, HIGH);
  pinMode(9, OUTPUT);
  digitalWrite(9, HIGH);  

}

BLYNK_WRITE(0)
{
  enableZone1 = param.asInt();
}

BLYNK_WRITE(1)
{
  timerZone1 = param.asInt();
}

BLYNK_WRITE(2)
{
  manualZone1 = param.asInt();
}



BLYNK_WRITE(3)
{
  if (param.asInt()) {
    digitalWrite(3, LOW);
    Blynk.virtualWrite(13, HIGH);
  } else {
    digitalWrite(3, HIGH);
    Blynk.virtualWrite(13, LOW);
  }
}

BLYNK_WRITE(4)
{
  if (param.asInt()) {
    digitalWrite(4, LOW);
    Blynk.virtualWrite(14, HIGH);
  } else {
    digitalWrite(4, HIGH);
    Blynk.virtualWrite(14, LOW);
  }
}

BLYNK_WRITE(5)
{
  if (param.asInt()) {
    digitalWrite(5, LOW);
    Blynk.virtualWrite(15, HIGH);
  } else {
    digitalWrite(5, HIGH);
    Blynk.virtualWrite(15, LOW);
  }
}


void loop()
{
  Blynk.run(); // All the Blynk Magic happens here...

if ((enableZone1 == HIGH) && (timerZone1 == HIGH))  {
    Blynk.virtualWrite(23, HIGH); }
    else  {
    Blynk.virtualWrite(23, LOW);  }


}

there is a link for your error: http://tiny.cc/blynk-bug#flood

Thanks Pavel,

I was finally able to get that working. I posted the complete code on our Missing Virtual Pins thread as I was able to duplicate the problem.

R

1 Like

Hey Pavel,

I apologize for grabbing an old thread…

It has been a awhile since I checked in and I see many positive changes. Congratulations on all the progress! I can’t seem to get at any of my old projects. I previously logged in under "arduino@rapgar.com". Have all these old projects been purged?

Thx,
rapgar

@rapgar Hello. Look like yes. You need to create account again.