Question related to Blynk app button working

• Arduino UNO with Serial USB: Proteus Simulation
• Smartphone OS: Android
• Blynk server
• Blynk Library version: Latest


#define BLYNK_PRINT SwSerial


#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX

#include <BlynkSimpleStream.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "XXXXXXXXXXXXXXXz";
const int tempsensor_val = A0;
const int ldr_val = A1;
const int water_val = A2;
const int lamppin = 13;
const int heatpin = 12;
const int fanpin = 7;
const int shadingpin = 5;
const int pumppin = 6;


BlynkTimer timer;




 

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEventa()
{
  int sensorData1 = analogRead(tempsensor_val);
  float tempData = (sensorData1/1024.0)*5000/10;
  
 
  
  
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, tempData);
  
}
void myTimerEventb()
{
  int ldrData = analogRead(ldr_val);
  
  Blynk.virtualWrite(V6, ldrData);
}
void myTimerEventc()
{
  int waterData = analogRead(water_val);
  
  Blynk.virtualWrite(V7, waterData);
}

BLYNK_WRITE(V8)
{
  int pinValue = param.asInt();
  if(pinValue==1){
    digitalWrite(heatpin, HIGH);
     
  } else {
    digitalWrite(heatpin, LOW); 
  }
 
  // process received value
}
BLYNK_WRITE(V9)
{
  int pinValue1 = param.asInt();
  if(pinValue1==1){
    digitalWrite(lamppin, HIGH);
     
   
  } else {
    digitalWrite(lamppin, LOW); 
  }
 
  // process received value
}
BLYNK_WRITE(V10)
{
  int pinValue2 = param.asInt();
  if(pinValue2==1){
    digitalWrite(pumppin, HIGH);
     
  } else {
    digitalWrite(pumppin, LOW); 
  }
 
  // process received value
}
BLYNK_WRITE(V11)
{
  int pinValue = param.asInt();
  if(pinValue==1){
    digitalWrite(fanpin, HIGH);
     
  } else {
    digitalWrite(fanpin, LOW); 
  }
 
  // process received value
}
BLYNK_WRITE(V12)
{
  int pinValue = param.asInt();
  if(pinValue==1){
    digitalWrite(shadingpin, HIGH);
     
  } else {
    digitalWrite(heatpin, LOW); 
  }
 
  // process received value
}



void setup()
{
  // Debug console
  SwSerial.begin(9600);
  pinMode(tempsensor_val, INPUT);
  pinMode(ldr_val, INPUT);
  pinMode(water_val, INPUT);
  pinMode(lamppin, OUTPUT);
  pinMode(heatpin, OUTPUT);
  pinMode(fanpin, OUTPUT);
  pinMode(pumppin, OUTPUT);
  pinMode(shadingpin, OUTPUT);

  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  Blynk.begin(Serial, auth);

  // Setup a function to be called every second
  timer.setInterval(2000L, myTimerEventa);
  timer.setInterval(2000L, myTimerEventb);
  timer.setInterval(2000L, myTimerEventc);
  
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

So what I want to achieve is that when I will create an other button in the blynk app with virtual pin 13 and when the button is off only then will the other 5 blynk buttons , as described in the code, work. When virtual pin 13 is high, I want them to remain unresponsive…

is there any way, I can do this?

Edit: It’s possible push a virtual button and disable other button? - Need Help With My Project - Blynk Community Found this link

Using segmented switch will be better and will simplified your code.
Else, you have turn low all button in your code.

BLYNK_WRITE(V8)
{
Blynk.virtualWrite((V9, LOW);
Blynk.virtualWrite((V10, LOW);
.
.
}

OMG @Blynk_Coeur where are your backticks!!

:rofl: :rofl: :rofl:

Pete.

It’s not possible to disable buttons in Blynk, but it is possible to ignore button presses if you use virtual pins.
You can also change the colour of a button to simulate it being “greyed out” using the widget properties functionality.

To ignore the button presses if the widget attached to pin V13 is off, you’d set a global flag variable, then test that variable when the BLYNK_WRITE(vPin) callbacks for any of the other buttons are triggered. If the flag variable is true then proceed to process the button press, if not then flip the button back to its previous state.

Pete.

Sorry Pete, I know, I know :joy:
I’ve a new phone and I tried to find gboard backticks, unfortunately, I couldn’t find them.
i will correct this ASAP , when I’ll be back to my computer :joy:
Maybe I’ve to install QWERTY keyboard?

My answer is completely wrong :joy:
I thought he was asking for button state :crazy_face:
It was 5AM when I replied :last_quarter_moon_with_face::last_quarter_moon_with_face:

Which explains why you’re getting yout BLYNK_WRITE(vPin) commands mixed-up with Blynk.virtualWrite(vPin) commands?

:crazy_face:

Coffee required…:coffee:

Pete.

1 Like

Oops, I was a zombie :scream::scream::rofl:

thanks for this answer though I did need all buttons to turn low

1 Like

Thank you for the reply. I have done this exactly and it works!

2 Likes

Yes you can !

BLYNK_WRITE(V8)
{
Blynk.virtualWrite((V9, LOW);
Blynk.virtualWrite((V10, LOW);
Blynk.virtualWrite((V11, LOW);
Blynk.virtualWrite((V12, LOW);
//your code
}

BLYNK_WRITE(V9)
{
Blynk.virtualWrite((V8, LOW);
Blynk.virtualWrite((V10, LOW);
Blynk.virtualWrite((V11, LOW);
Blynk.virtualWrite((V12, LOW);
//your code
}

and so on …