Hi Guys,
I’m sure someone had a simple answer to my question but I’ve been struggling to find it.
I have an existing sketch that works well on my Arduino but have just been introduced to BLYNK. I want to integrate it and can quickly upload the standard LED ON/OFF blynk sketch and it works great. What I’m struggling with is how to have BLYNK trigger more complex events.
In my tests I have asked a switch on the app to make pin 12 HIGH. Then i’m using an IF statements on the Arduino to request that IF pin 12 is high then flash the LED on pin 13. This doesnt seem to work
Can anyone tell me how I perform this simple task? I can then use this as a base to build on.
Thanks
James
This is the code I would like to trigger in my existing sketch.
if (PIN IS MADE HIGH BY BLYNK**)) {
digitalWrite(Warning, HIGH);
delay(1000);
digitalWrite(DoorDir, LOW); //defines the stepper motor direction
while (Distance < 5000L) { //this while loop is creating the pulses for a stepper motor driver.
digitalWrite(DoorPulse, HIGH);
delayMicroseconds (100);
digitalWrite(DoorPulse, LOW);
delayMicroseconds (100);
Distance = Distance + 1;
delayMicroseconds(100);
}
digitalWrite(PlatformUp, HIGH);
delay(1000);
digitalWrite(PlatformUp, LOW);
delay(1000);
digitalWrite(Warning, LOW);
delay(1000);
Distance = 0;
}
Thanks Nicolas, I have read about the virtual pins but dont understand how to implement them. Can simply write
if(v1==HIGH)
DO STUFF
Please use the code format in the forum, like this:
press ` 3 times write “cpp” at the start and at the end of the code write more 3 for it to be formated like this:
#include <blabla>
code
code code
code
Example:
´´´cpp
include
code
code code
code
´´´
So, what you need to do is this:
First you need to set up a blynk read function like this:
To send data from hardware to app:
BLYNK_READ(V5) // Widget in the app READs Virtal Pin V5 with the certain frequency
{
// This command writes a value to Virtual Pin V5
Blynk.virtualWrite(V5, Value);
}
It will update automaticaly with the time you have selected on the app, and there you write the values you want the app to read.
To send data from app to hardware:
BLYNK_WRITE(V6) // Widget in the app Writes Virtal Pin V6 with the certain frequency (PUSH most likely)
{
// This command writes the value from V6
int pinData = param.asInt();
if(pinData = 1)
//DO STUFF
}
so in your case:
BLYNK_WRITE(V6) // Widget in the app Writes Virtal Pin V6 with the certain frequency (PUSH most likely)
{
// This command writes the value from V6
int pinData = param.asInt();
if (pinData == 1)) {
digitalWrite(Warning, HIGH);
delay(1000); //Don't use delay with Blynk, use SimpleTimer
digitalWrite(DoorDir, LOW); //defines the stepper motor direction
while (Distance < 5000L) { //this while loop is creating the pulses for a stepper motor driver.
digitalWrite(DoorPulse, HIGH);
delayMicroseconds (100); //Don't use delay with Blynk, use SimpleTimer
digitalWrite(DoorPulse, LOW);
delayMicroseconds (100); //Don't use delay with Blynk, use SimpleTimer
Distance = Distance + 1;
delayMicroseconds(100); //Don't use delay with Blynk, use SimpleTimer
}
digitalWrite(PlatformUp, HIGH);
delay(1000); //Don't use delay with Blynk, use SimpleTimer
digitalWrite(PlatformUp, LOW);
delay(1000); //Don't use delay with Blynk, use SimpleTimer
digitalWrite(Warning, LOW);
delay(1000); //Don't use delay with Blynk, use SimpleTimer
Distance = 0;
}
}
Thanks Nicolas, sorry for the code insert error. I’ll have a go at this shortly and report how i get on.
Really appreciate your help so far.
James
You will need this lib for what you are doing: https://github.com/jfturcot/SimpleTimer