Blynk app GUI buttons

Hello, I’m trying to build IOT Christmas ornaments using a Particle Photon. I’d like them to be controlled via the Blynk app. There are a few things I want them to be able to do:

  1. Change colours depending on what I set in the Blynk app
  2. Blink in a pattern that I set in the Blynk app
  3. Change colours in a pattern I set in the Blynk app

In order to do all this, I need to be able to write code that can detect which button is pressed in the app.
So, I guess my big questions is how do I reference the button that’s in my GUI (in the Blynk app) in my code?

Any help would be awesome!!

Everything you need is covered in the blynk docs. I suggest you read it :slight_smile: judging by the question I can tell that you have not read it.

Good luck!
http://docs.blynk.cc/

1 Like

Thanks for the reply. I’ve been spending some time reading them and I’m still a bit confused.

I REALLY wish they just had a virtualRead command!!!
They have virtualWrite but no Read?!?!?!
It’s kinda ridiculous!!

I did find another forum post that said the solution is to use state syncing but I really don’t see how that’s a viable solution. Then, I found a post that said using param.asInt() will read a virtual pin.
However, I can’t figure out how to set which virtual pin I want to read. And, I can’t figure out how to read multiple virtual pins.

Again, thank you so much for the reply and the advice.

I think the terminology is confusing you slightly.
Take a look at this example in the Example Builder…
https://examples.blynk.cc/?board=Particle%20Photon&shield=Particle%20WiFi&example=GettingStarted%2FVirtualPinRead

Pete.

the thing is, that the blynk guys who developed the lib, have used to think from the app pov, not from the hardware pov.

when you see blynk.virtualwrite(vpin, value), than actually the hardware sends data on the respective virtual pin to the app.

and when you see blynk_read, then the app tries to read data from the hw.

a bit confusing at the beginning, but you can learn quickly if you understand the logic behind.

read the docs, do some very basic examples and you will understand.

We’ve sent you all the links on that matter in Facebook. Have you at least tried to read through them?

  1. http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/how-to-control-anything-with-blynk-app
  2. http://docs.blynk.cc/#blynk-main-operations-send-data-from-app-to-hardware
  3. Use old simple tool called “google search
  4. Youtube video https://www.youtube.com/watch?v=iueWEkM6cuQ
  5. Many other youtube videos

It’s just one simple construction:

BLYNK_WRITE(V1) // Button Widget is writing to pin V1
{
  int pinData = param.asInt(); //assign value from pin to variable called pinData
  
 if (pinData == 1){

 //do something when button is pressed

 } esle if (pinData == 0){

 // do something else when button is released

 }
}

I figured it out, thank you very much for your time and efforts!!
The Blynk forums are one of the best forums I’ve found so far!
Thank you all for your help.