note: the lambda has no capture-default
timer.setTimeout(2000L, [](){
^
/Users/saurabh/Documents/Arduino/harplyn-rtu/harplyn-rtu.ino:16:17: note: 'int pinX' declared here
void TurnOn(int pinX){
^
exit status 1
'pinX' is not captured
When you put “int” in front of a variable name it re-declares that variable, setting its value to zero.
When you do this within a function, any values you assign to that variable are only available within that function.
You need to use global variables, and not keep re-declaring them locally, if you want the values assigned to those variables to be available through your code.
Thanks for the Reply,
you may be miss interpreted my question.
I know that declaring the Global variable works. but i want to pass the parameter to that lamba expression.so that I can turn ON & OFF the different pins from the same function.without right separate function for each pin.
like this
@saurabh47 Of course with snippets, we don’t get the whole picture as to the whys I am also wondering what pulls the pin LOW and why it is not included in the function, but prior to the Lambda timer for even more compact code.
Anyhow, this whole passing parameters is new to me… well… I have seen it, but never used it… so I am learning as I watch this topic
If that’s the case then I’d just put an empty lambda timer function in there, which solves the problem of passing the pin variable value into the lambda function.
If that’s not the case them I’m clearly missing the point.
Personally, I much more of a longhand coder, including putting curly brackets on their own line, because I find that easier to visualise.
if you use empty Lambda function.in that case, it will not digitalwrite after 200ms delay.it executes the below code(digitalwrite) immediately.
I am avoiding delays.so it will not block other code.
Good point… use of such a short delay is unlikely to cause any “Blynk” issues… unless being called frequently?
I can see that… except I can also get lost in the code… so keeping everything related (grouped) seems to help for me. I think that is why I like the lambda… that and is sounds like shorthand for my favorite car, the Lambo At least I can say I can use one of them