MG995 + ESP8266 Code, need to know more please

Hi guys, i am pretty news with arduino and electronic but i have a little background with programmation.

I have fews question on this code, i take it on a website for example and want to work with to do what i want.

What i want it having 3 buttons on my blynk app to tilt my blinds on 3 position : Close up, Close down and open.

My question is : How i can determine to my button when i click on it, to turn CW 5 sec, on other button to turn CCW 5 sec and the other CW or CCW depending on what side was the last position to 2.5 sec.

My other question is : How the Int Pos; was determine ?

I search on the internet but never see something like that with Blynk.

Thank all

I have this code for starting :

#define BLYNK_PRINT Serial

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

char ssid[] = "XXXXXXXXXX";
char pass[] = "XXXXXXXXX";

Servo servo;

void MG995() {
int pos = 0;

for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees ,in steps of 1 degree
servo.write(pos); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
servo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position

int pinValue = param.asInt();
if (pinValue == 1) { // if Button sends 1
MG995(); // start the function cradle; // Run rest of show in-between waiting for this loop to repeat or quit.
int pinValue = 0; // Set V3 status to 0 to quit, unless button is still pushed (as per below)
Blynk.syncVirtual(V3); // ...Then force BLYNK_WRITE(V3) function check of button status to determine if repeating or done.

void setup()
// Debug console

Blynk.begin(auth, ssid, pass);

servo.attach(15); //attaches servo to pin 15 (D8 on node mcu)

void loop()

Do you have a standard MG995 that only turns approximately 180 degrees or do you have one modified for continuous rotation so it spins round and round? The code is written for a standard servo not a modified one and it is taken straight from the Sweep example code from the IDE.

Since you talk about moving for 5 seconds rather than to a particular position it sounds like you are using a continuous rotation servo so things are done differently. The value in write(pos) affects the speed of the servo NOT the position the servo goes to.


it is modified to be continous.

Can you help me ? i don't want any sketch all done, just some hint about it, i want to learn.