Hello all !
for my first project, i have write a Dog Feeder, and i’ve write a function for reversing motor when the current is overload (in some case, the Wheel is blocking, to avoid this -> change rotation
but !
it work with a simple process into void section, and not working into BLYNK_WRITE section
When i press V0 virtual button, it launch doFeed function, and into this function , testCourantMoteur check the current of motor and it change (or not) a flag.
into the serial monitor, i can’t the value of current, as if doesn’t launch the checkCurrentFunction !
I’ll rip my hair out!
i have extract some code from my project, if you have an idea, i take !
ps : if you think i must post all code, tell me.
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>
#include <BlynkSimpleEsp8266.h>
#include <WidgetRTC.h>
#include <TimeLib.h>
#include <SimpleTimer.h>
ESP8266WebServer httpServer(80);
ESP8266HTTPUpdateServer httpUpdater;
SimpleTimer timer;
WidgetRTC rtc;
WidgetLCD lcd(V13);
int isFirstConnect = true;
boolean flag_arret = false;
boolean flag_running = false;
boolean flag_sens = false;
boolean flag_sens_canBeChanged = true;
bool flag_doManOK = false;
int courantMoteur1 = 0;
int courantMoteur2 = 0;
const int SeuilCourrant = 100;
int dureMoteur1 = 33000;
const byte buttonPin = D3;
const byte ledBP = D1;
const byte ENA = D5;
const byte IN1 = D6;
const byte IN2 = D7;
const int current = A0;
void setup()
{
// Affichage version dans console
Serial.begin(115200);
Serial.println("V 3.2 Blynk version / OTA version");
Serial.println();
//connection au serveur Blynk
Blynk.begin(auth, ssid, pass);
// Begin synchronizing time
rtc.begin();
// Declaration PINS
pinMode(buttonPin, INPUT_PULLUP); // start feeding
pinMode(ledBP, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(current, INPUT);
//pinMode(CapteurIR, INPUT);
// Moteurs L298N
pinMode(ENA,OUTPUT);
pinMode(IN1,OUTPUT);
pinMode(IN2,OUTPUT);
// Led OFF - Moteurs OFF
digitalWrite(ledBP,LOW);
digitalWrite(ENA,LOW);// Moteur A - Ne pas tourner (désactivation moteur)
}
// Current test for Motor A
void testCourantMoteur ()
{
courantMoteur1 = analogRead(current);
if(courantMoteur1 < SeuilCourrant)
{
Serial.println(courantMoteur1);
flag_sens_canBeChanged = true;
return;
}
if (flag_sens_canBeChanged && courantMoteur1 >= SeuilCourrant)
{
Serial.print("Moteur bloqué / changement sens : ");
Serial.println(flag_sens);
Serial.println(courantMoteur1);
flag_sens = not(flag_sens);
flag_sens_canBeChanged = false;
}
}
BLYNK_WRITE(V0)
{
if(param.asInt() == 1) {
doFeed();
Blynk.virtualWrite(V0, 0);
}
}
void doFeed()
{
Serial.println("Fonction Blynk Auto moteur");
testCourantMoteur ();
Serial.println("Courant : ");
Serial.println(courantMoteur1);
startOfMotor = millis();
while(millis() != (startOfMotor+dureMoteur1))
{
if (flag_sens == false)
{
//Moteur A : ON
digitalWrite(ENA,HIGH);
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
}
else
{
//Moteur A : ON
digitalWrite(ENA,HIGH);
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
}
yield();
}
digitalWrite(ledBP, LOW);
digitalWrite(ENA,LOW);
Serial.println("Fin de fonction auto blynk ");
}
void loop()
{
Blynk.run();
timer.run();
}