Hi,
I would like to know how do i make sure the me ESP8266 remembers the last button pressed on the Blynk app (V1 or V2) and does nothing if i give the same command twice. For Example if V1 was pressed last the motor will do nothing if V1 is pressed again.
Thanks #using-arduino
you can sync the pin state from the Blynk Clound
#include <Stepper.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Arduino.h>
#define BLYNK_PRINT Serial
Stepper my_Stepper(200, 15, 13, 12, 14);
bool Right = false;
bool Left = false;
char auth[] = "";
char ssid[] = "";
char pass[] = "";
void disable_motor()
{
digitalWrite(15, LOW);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(14, LOW);
}
void setup(){
Serial.begin(9600); // baudrate for serial comunication
Blynk.begin(auth, ssid, pass); // network information
my_Stepper.setSpeed(200); // Speed for stepper motor
}
BLYNK_WRITE(V1){ // read input from virtual pin V1
Right = param.asInt(); // assigning incoming value from pin V§1 to a variable
}
BLYNK_WRITE(V2){ // read input from virtual pin V2
Left = param.asInt(); // assigning incoming value from pin V0 to a variable
}
void Stepper1 (int Direction, int Rotation){ // function for stepper motor control with 2 parameters
for (int i = 0; i < Rotation; i++){ // for loop
my_Stepper.step(Direction * 200); // 200 is 360 degree => change value if smaller then 360 degree is needing
Blynk.run();
}
}
void loop() {
Blynk.run();
if (Right){ // if condition
Stepper1(1, 20); // steppermotor rotates 10 times 360 degree right
Serial.println("Curtain DOWN");
}
delay(10); // delay 20ms
if (Left){ // if condition
Stepper1(-1, 20); // steppermotor rotates 10 times 360 degree left
Serial.println("Curtain UP");
}
delay(10); // delay 20ms
disable_motor(); // always desable stepper motors after use to reduce power consumption and heating
}
This is my sketch... what changes do i make?
#include <Stepper.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Arduino.h>
#define BLYNK_PRINT Serial
Stepper my_Stepper(200, 15, 13, 12, 14);
bool Right = false;
bool Left = false;
char auth[] = "";
char ssid[] = "";
char pass[] = "";
void disable_motor()
{
digitalWrite(15, LOW);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(14, LOW);
}
void setup(){
Serial.begin(9600); // baudrate for serial comunication
Blynk.begin(auth, ssid, pass); // network information
my_Stepper.setSpeed(200); // Speed for stepper motor
}
BLYNK_WRITE(V1){ // read input from virtual pin V1
Right = param.asInt(); // assigning incoming value from pin V§1 to a variable
}
BLYNK_WRITE(V2){ // read input from virtual pin V2
Left = param.asInt(); // assigning incoming value from pin V0 to a variable
}
void Stepper1 (int Direction, int Rotation){ // function for stepper motor control with 2 parameters
for (int i = 0; i < Rotation; i++){ // for loop
my_Stepper.step(Direction * 200); // 200 is 360 degree
=> change value if smaller then 360 degree is needing
Blynk.run();
}
}
void loop() {
Blynk.run();
if (Right){ // if condition
Stepper1(1, 20); // steppermotor rotates 10 times 360 degree right
Serial.println("Curtain DOWN");
}
delay(10); // delay 20ms
if (Left){ // if condition
Stepper1(-1, 20); // steppermotor rotates 10 times 360 degree left
Serial.println("Curtain UP");
}
delay(10); // delay 20ms
disable_motor(); // always desable stepper motors after use to reduce power
consumption and heating
}
Your topic has been moved to a more suitable location on the forum as this has nothing to do with Avrdude, stk500 or Bootloader
Please edit your posts, select all code and click the <CODE>
button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and the forum software will display it correctly.
Is there a difference between the code in post #4 and post #3 ?
Hi,
Thank you for the advice.
Both the sketches are same.
Edit the post and add the code tags please. If the code in the other post is identical, please delete it.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.