0

I wrote a sketch for controlling the stepper motor under the controls of the Blynk application, the sketch was compiled but there was a problem in that no control was taking place. Receipts and controls occur on virtual pins V1, V2, V3. (The problem is that nothing is controlled), please help solve the problem. enter image description here enter image description here enter image description here enter image description here

//#include <Stepper.h>
//#define BLYNK_WRITE
//#include <ESP8266WiFi.h>
//#include <BlynkSimpleEsp8266.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
Stepper myStepper(stepsPerRevolution, 1, 2, 3, 4);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "[private]";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "S30mini";
char pass[] = "12345678";
int pinData;
int pinData1;
int pinData2;
BLYNK_WRITE(V3) //Button Widget is writing to pin V1
{
 int pinData = param.asInt(); 
 }
BLYNK_WRITE(V2) //Button Widget is writing to pin V1
{
 int pinData1 = param.asInt(); 
 }
BLYNK_WRITE(V1) //Button Widget is writing to pin V1
{
 int pinData2 = param.asInt(); 
 }
void setup()
{
 // Debug console
 Serial.begin(115200);
 Blynk.begin(auth, ssid, pass);
}
void loop()
{ 
 Blynk.run();
 // map it to a range from 0 to 100:
 int motorSpeed = map(pinData, 0, 1023, 0, 100);
 // set the motor speed:
 if (motorSpeed > 0) {
 myStepper.setSpeed(motorSpeed);
 // step 1/100 of a revolution:
 myStepper.step(stepsPerRevolution / 100);
 }
 if (pinData1 == 1){
 myStepper.step(stepsPerRevolution);
 }
 if (pinData2 == 1){
 myStepper.step(-stepsPerRevolution);
 }
}
jose can u c
6,9742 gold badges16 silver badges27 bronze badges
asked Jan 2, 2019 at 14:57

1 Answer 1

1

By prefixing your pinData variables with int, you are declaring local variables in your BLYNK_WRITE() functions, whose scope is only in that function. The local version is written to, instead of the global.

To fix this, do not declare a new variable in BLYNK_WRITE():

BLYNK_WRITE(V3) //Button Widget is writing to pin V1
{
 pinData = param.asInt(); 
}
BLYNK_WRITE(V2) //Button Widget is writing to pin V1
{
 pinData1 = param.asInt(); 
}
BLYNK_WRITE(V1) //Button Widget is writing to pin V1
{
 pinData2 = param.asInt(); 
}
answered Jan 2, 2019 at 15:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.