I am creating a Drone with Blynk.
Here’s the code.(The actual code is too long so I summarized it into a function called main_loop().
void setup()
{
M_1.attach(3);
M_2.attach(9);
M_3.attach(10);
M_4.attach(11);
delay(1000);
M_1.write(30);
M_2.write(30);
M_3.write(30);
M_4.write(30);
delay(5000);
throttle=0;
normal();
pinMode(w_led, OUTPUT);
digitalWrite(w_led, HIGH);
SerialBLE.begin(9600);
Blynk.begin(SerialBLE, auth);
//Serial.println("Waiting for connections...");
//delay(1000);
digitalWrite(w_led, LOW);
led.on();
Wire.begin();
mpu.begin();
mpu.calcGyroOffsets();
delay(2000);
while (onoff == 0)
{
Blynk.run();
}
digitalWrite(w_led, LOW);
th_1 = 0;
th_2 = 0;
th_3 = 0;
th_4 = 0;
throttle = 350;
normal();
delay(1000);
led.off();
c++;
}
void loop()
{
Blynk.run();
main_loop();
}
According to the code the four motors should first calibrate then the bluetooth will be setup and to indicate that the setup has started the led at D12 will switch on. But, whenever I connect with bluetooth and it starts with the throttle, the motors stop and the led again starts. Any suggestions what is the actually the problem. In my code or that Blynk.run() calls setup().