Hi guys,
Im building a mobile control car using wifi and arduino. The problem is to make the physical LEDs (signal indicator) flashing when the virtual button is pressed.
The mobile robot consists of:-
Arduino Nano
ESP-01 ESP8266
Logic Converter
L298N motor Driver
LEDs (Headlight, Taillight, Signal)
Android 8.1
The headlight and the taillight working well through directly assigned pin on the app. Only the signal indicator is not flashing.
#define BLYNK_PRINT Serial
#include<ESP8266_Lib.h>
#include<BlynkSimpleShieldEsp8266.h>
char auth[] = "XXXX";
char ssid[] = "XXXX";
char pass[] = "XXXX";
#include<SoftwareSerial.h>
SoftwareSerial EspSerial (2, 3); // here RX, TX
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
#define led1 A0 //
#define led2 A1 //
int ledState = LOW; //
const long interval = 400; //
unsigned long previousMillis = 0; //
void setup()
{
pinMode(led1, OUTPUT); //
pinMode(led2, OUTPUT); //
Serial.begin(9600);
delay(10);
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
}
void loop()
{
Blynk.run();
}
BLYNK_WRITE(V0)
{
if (param.asInt() == 1)
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
if (ledState == LOW)
{
ledState = HIGH;
}
else
{
ledState = LOW;
}
digitalWrite(led1, ledState);
digitalWrite(led2, !ledState);
}
}
else
{
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
}
}