#include <WiFi.h>
#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD " "
int status = WL_IDLE_STATUS;
int LED_Pin[]={25,33,32,23,22,21,19,18,5,4,2,15};
int x=0;
int i=0;
void InitWiFi()
{
Serial.println("Connecting to AP");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while(WiFi.status() != WL_CONNECTED) {
Serial.print(".");
digitalWrite(LED_Pin[x], HIGH);
delay(500);
digitalWrite(LED_Pin[x], LOW);
x++;
if ( x == 12)
{
x=0;
}
}
Serial.println("");
Serial.println("Connected to AP");
}
void reconnect() {
status = WiFi.status();
if ( status != WL_CONNECTED) {
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while(WiFi.status() != WL_CONNECTED) {
Serial.print(".");
digitalWrite(LED_Pin[x], HIGH);
delay(500);
digitalWrite(LED_Pin[x], LOW);
x++;
}
Serial.println("");
Serial.println("Connected to AP");
}
}
void setup() {
Serial.begin(115200);
Serial.println("");
for (i=0; i <= 12; i++)
{
pinMode(LED_Pin[i], OUTPUT);
}
InitWiFi();
}
void loop() {
delay(1000);
if (WiFi.status() != WL_CONNECTED){
reconnect();
}
else {
Serial.print("WiFi sudah terkoneksi dengan: ");
Serial.println(WIFI_SSID);
Serial.print("IP:");
Serial.println(WiFi.localIP());
for (i=0; i < 13; i++)
{
digitalWrite(LED_Pin[i], HIGH);
}
}
}