in my Project I want to receive the actual value from the Step Control widget, and with this value i want to trigger my Virtual pins in my program. That means if i get the value 2 from my stepper i want to activate the V2.
Is there a way to do that? Or do you have another idea to do that?
Here is my Code so far:
//#define BLYNK_PRINT Serial <------ comment here
#define BLYNK_USE_DIRECT_CONNECT
#include <BlynkSimpleSerialBLE.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "bc91216cb249448fb6952f200dca808f";
int var = 0;
#define SerialBLE Serial // Set Serial object
void setup()
{
for(int i = 0;i<55;i++){
pinMode(i,OUTPUT);
digitalWrite(i,HIGH);
}
SerialBLE.begin(9600); // Set Serial baud rate
Blynk.begin(auth, SerialBLE);
Blynk.virtualWrite(V1,var);
}
void loop()
{
Blynk.run();
}
BLYNK_WRITE(V1)
{
if(var == 0){
digitalWrite(2,!HIGH);
digitalWrite(3,!HIGH);
digitalWrite(4,!HIGH);
}else if(var ==1){
digitalWrite(5,!HIGH);
digitalWrite(6,!HIGH);
digitalWrite(7,!HIGH);
}else if(var ==2){
digitalWrite(8,!HIGH);
digitalWrite(9,!HIGH);
digitalWrite(10,!HIGH);
}
}
BLYNK_WRITE(V0){
// receive the step value as param.asInt() and then trigger a virtual pin with syncVirtual()
Blynk.syncVirtual(param.asInt());
}
BLYNK_WRITE(V1){
// when step widget stop on "1" it will run code here.
}
BLYNK_WRITE(V2){
// when step widget stop on "2" it will run code here.
}
// etc
In case you got your description wrong and you instead want simple control of digitalPins instead, then you do not need syncVirtual.
BLYNK_WRITE(V0){
// receive the step value as param.asInt() and then use switch to run different code
switch(param.asInt()){
case 1:
// when step widget stop on "1" it will run code here.
break;
case 2:
// when step widget stop on "2" it will run code here.
break;
case 3:
// when step widget stop on "3" it will run code here.
break;
}
}
@Kasomatro You have a range of 0-29, but also have the Send Step toggled to YES… when toggled YES, it does just that, sends a simple -1 or 1 when the widget is accordingly triggered (very useful for specific situations).
NOTE: the value on the widgets upper right corner keeps changing as normal… confusing? yes, and that has been an issue mentioned to the developers in the past.
If you want an incrementing/decrementing value from 0-29, then toggle NO on the Send Step option: