BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       👉 SKETCH BUILDER

Need help with my code

Hi !

I’m making system with old print head. I want block working with buton. I can see state buton ( HIGH or LOW ), but only stop fonction work no matter pin state. Without digiyal read it’s working. Maybe problem with timer or some thing like this ?

Thanks

//D6 In2
//D7 In3
//D8 In4



#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#define In1   5  //D1 IN1
#define In2   4  //D2 IN2
#define In3    13  //D7 IN3
#define In4      15  //D8 IN4
#define Ena 5
#define Enb 4

char auth[] = "bqeWhNrLI8cIa2ECQYkK-4dnmtaHVQXM";  //Blynk Authentication Token
char ssid[] = "indoor";           //WIFI Name
char pass[] = "indoorwifi";           //WIFI Password

int minRange = 312;
int maxRange = 712;

//int minspeed = 500;
//int maxspeed = 1020;
//int nospeed = 0;

//int RightMotorSpeed = D5   //14
//int RightMotorDir = D6   //12
//int LeftMotorSpeed = D7   //13
//int LeftMotorDir = D8   //15

void moveControl(int x)
{

  //No Move
  if (x == 512 && digitalRead(13) == LOW )
  {
    digitalWrite(In1 , HIGH);
    digitalWrite(In2 , HIGH);
    

    Serial.println ("stop");
  }

  //GAUCHE
  else if (x > 1000 && digitalRead(13) == LOW)
  {
     //digitalWrite(15 , HIGH);
     digitalWrite(In1 , HIGH);
    digitalWrite(In2 , LOW);
   
    Serial.println ("DROITE");
  }


  //DROITE
  else if (x < 23 && digitalRead(13) == LOW)
  {
    //digitalWrite(15 , HIGH);
    digitalWrite(In1 , LOW);
    digitalWrite(In2 , HIGH);
    
    Serial.println ("GAUCHE");
  }
}


void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass, IPAddress(10, 3, 141, 1), 8080);

  pinMode(In1, OUTPUT);
  pinMode(In2 , OUTPUT);
  pinMode(In3, OUTPUT);
  pinMode(In4, OUTPUT); 
  pinMode(15, OUTPUT);
  digitalWrite(In1 , HIGH);
  digitalWrite(In2 , HIGH);
   pinMode(13, INPUT_PULLUP);

     
}


void loop()
{
  Blynk.run();
  if (digitalRead(13) == LOW) // Si ARDUINOPIN est BAS (0V)
{
  Serial.println("LOW"); //Afficher avec retour à la ligne => OFF
}
else {         // Sinon (ARDUINOPIN est HAUT (5V)
Serial.println("HIGH"); //Afficher avec retour à la ligne => ON
}
  
 //Met le programme en pause pendant 100ms avant de reboucler 

  
}
  




BLYNK_WRITE(V1)
{
  int x = param[0].asInt();
  moveControl(x);
}```

Int x = param.asInt();

Beautiful ! Thanks

1 Like