Using state of one pin to in a different function

Hi,
I’m new here and I couldn’t find the answer to my question - not because it wasn’t probably asked before, but because I have no idea what to search for… This should have a simple solution though.

I use the BLYNK_WRITE(V1) to define the brightness of my LED. I then want it to be delayed for some time afterwards. I want the delay to be set by a different widget, but I’m having trouble doing that.
Is there a way to pull the information of a virtual pin?

Also, my plan is to use two widgets to control a linear actuator. My goal is to set the velocity of its motion and the duration of each stroke using two widgets, but right now I’m unable to understand of to use the state of virtual pins in a more complex function. Is this possible?

Here is the code of the LED I’m trying to manipulate (with no luck):


BLYNK_WRITE(V1)
{
  int brightness = param.asInt(); 
  analogWrite(led, brightness);
  delay(duration); // duration should be pulled from the 2nd widgets on V2
  analogWrite(led, 0);

}

BLYNK_WRITE(V2)
{
  int duration = param.asInt();
  duration = 1000 * duration 
}

Thanks in advance!

@Nir_Livne the characters you’ve used at the beginning and end of your code are the wrong ones. Please edit your post, using the pencil icon at the bottom, and replace them with triple backticks, which look like this:
```

Search for ”variable scope”.

Pete.

I will do that, thanks for the quickest reply on the WWW!

:grinning:

By putting int in front of your variable names you are declaring them within the BLYNK_WRITE functions, which makes them local to that function.

If you move the declarations to the top of your code they become global variables and accessible anywhere within your code.
The thing to look out for is that if you keep the int in front of these lines within your functions you won’t get a compilation error, but you are still re-declaring the variables locally so limiting their scope to within that variable.

Pete.