BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Reading state of virtual Push Buttons


#1

Hello. I am trying to control a stepper using Wemos D1 mini microcontroler and the Blynk app. Basically what I want is, to have to push buttons on the app, and while the first is being hold, the stepper to move in one direction, when the other is being hold, the stepper to move in the other direction. I have written the functions for driving the stepper and the only thing left to do is to read if the buttons are being pushed. Adittionally, I have two diodes that should be HIGH for each button pushed.

//BLUE - IN1 -> D8 - GPIO15
//PINK - IN2 -> D7 - GPIO13
//YELLOW - IN3 -> D6 - GPIO12
//ORANGE - IN4 -> D5 - GPIO14

//forward -> D1 - GPIO 5
//backward -> D2 - GPIO 4

int blue = 15;
int pink = 13;
int yellow = 12;
int orange = 14;
int forwardled = 5;
int backwardled = 4;
int i = 0;

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "d5f6e4c9da9xxxxxx51db4292";
const char* ssid = "WLAN_5DD6D2";
const char* pass = "impAlA_67";

BLYNK_WRITE(V1)
{
  int pinValueF = param.asInt(); // assigning incoming value from pin V1 to a variable
  while (pinValueF == HIGH)
  {
    forward();
    digitalWrite(forwardled, HIGH);
  }
  
}
BLYNK_WRITE(V2)
{
  int pinValueB = param.asInt(); // assigning incoming value from pin V1 to a variable
  while (pinValueB == HIGH);
  {
    backward();
    digitalWrite(backwardled, HIGH);
  }
}
void setup() {

  Serial.begin(115200);
  delay(10);  
  
  Blynk.begin(auth, ssid, pass);
  
  pinMode(blue, OUTPUT);
  pinMode(pink, OUTPUT);
  pinMode(yellow, OUTPUT);
  pinMode(orange, OUTPUT);
  pinMode(forwardled, OUTPUT);
  pinMode(backwardled, OUTPUT);
  
}

void loop() {
    Blynk.run();
}


//steps 
void step1(){
  digitalWrite(blue,HIGH);
  digitalWrite(pink,HIGH);
  digitalWrite(yellow,LOW);
  digitalWrite(orange,LOW);
  delay(5);
}
void step2(){
  digitalWrite(blue,LOW);
  digitalWrite(pink,HIGH);
  digitalWrite(yellow,HIGH);
  digitalWrite(orange,LOW);
  delay(5);
}
void step3(){
  digitalWrite(blue,LOW);
  digitalWrite(pink,LOW);
  digitalWrite(yellow,HIGH);
  digitalWrite(orange,HIGH);
  delay(5);
}
void step4(){
  digitalWrite(blue,HIGH);
  digitalWrite(pink,LOW);
  digitalWrite(yellow,LOW);
  digitalWrite(orange,HIGH);
  delay(5);
}
void forward(){
  step1();
  step2();
  step3();
  step4();
}
void backward(){
  step4();
  step3();
  step2();
  step1();
}
void keyPressForward(){
  for(i=0;i<25;i++) forward();
}
void keyPressBackward(){
  for(i=0;i<25;i++) backward();
}

#2

Welcome to the Blynk Forum. Unfortunately you seem to have missed reading the Welcome Topic, in which it explains how to format any posted code for proper forum viewing… I have fixed your post this time (and blocked out part of your Auth Code)


#3

As for your “question?” this forum is NOT here to help write your code, or even teach you how to program, wire up hardware or otherwise duplicate the many hundreds of “How tos” already out there.

If you have a question pertaining to how a particular Widget or Blynk function works, or how to better utilise it, please ask, but be specific… i.e. reading the “state” and/or results of a Widget is done by the BLYNK_WRITE(vPIN) function (as you have seemingly already accomplished)

http://docs.blynk.cc/#blynk-firmware-virtual-pins-control-blynk_writevpin

You can also search this forum for the many other Stepper control topics that have been asked… there might be some answers already in them. Search for keywords like Stepper motor

Blynk - RE-SEAR-CH