Step Control Widget to trigger Virtual Pins

Hi there,

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);
      }
}

Thank you for reply.

This is simple using syncVirtual

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;
  }
}

1 Like

I tried both examples you gave me but it dosen’t work.
Maybe i have done something wrong in my App?

I am sure that blynk is working because i tried a simple BLYNK_WRITE with a button and it works.

Here is a screenshot of the step control configuration:

Thanks for reply.

@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.

On

Step Step1

If you want an incrementing/decrementing value from 0-29, then toggle NO on the Send Step option:

Off

21 22

The simple code I used to demonstrate this:

BLYNK_WRITE(V46)
{
  Blynk.virtualWrite(V45, param.asInt() );
}

Many Thanks guys it works!!!