#include <WiFi.h>
#include <WiFiClient.h>
#include <PubSubClient.h>
int YLED=19;
int GLED = 18;
int RLED = 23;
int GledState = LOW; // ledState used to set the Green LED
int RledState = LOW; // ledState used to set the Red LED
int YledState = LOW; // ledState used to set the YellowLED
long GpreviousMillis = 0; // will store last time Green LED turn on
long RpreviousMillis = 0; // will store last time Red LED turn on
long YpreviousMillis = 0; // will store last time Yellow LED turn on
long previousMillis = 0; // store for analog
int Ginterval = 2000; // interval for green ld; this change according to qn
int Rinterval = 1000; // interval for red led; this change according to qn
int Yinterval = 2000; // interval for yellow led; this change according to qn
int interval = 500; // interval for analog
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* hostname = "broker.hivemq.com";
WiFiClient espClient;
PubSubClient client(espClient);
const char* espClientName = "esp32_YOURNAME"; // *** Remember to Change the name to yoru name
int PORTNUM = 1883;
void setup()
{
Serial.begin(9600);
delay(5000);
pinMode(RLED, OUTPUT);
digitalWrite(RLED , HIGH);// off the Red Led
pinMode(GLED, OUTPUT);
digitalWrite(GLED , HIGH); // off the Green LED
pinMode(YLED, OUTPUT);
digitalWrite(YLED , HIGH); // off the Green LED
}
void loop()
{
long currentMillis = millis();
if ( currentMillis - RpreviousMillis >= Rinterval) // this is for the RED LED *8 Change according to Qn
{
RpreviousMillis = currentMillis;
if (RledState == LOW)
{
RledState = HIGH;
digitalWrite(RLED,RledState);
}
else
{
RledState = LOW;
digitalWrite(RLED,RledState);
}
}
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
int adcRes = analogRead(A5);
Serial.print("Local: ");
Serial.println( adcRes );
char str[4];
sprintf(str, "%d", adcRes);
}
}