#if defined(ESP8266)
#include <ESP8266WiFi.h>
#elif defined(ESP32)
#include <WiFi.h>
#endif

#define led1 27
#define led2 26 
#define led3 25
#define led4 33
#define led5 32
#define led6 23
#define led7 22 
#define led8 21
#define led9 19 
#define led10 18
#define led11 5
#define led12 4

#define WIFI_SSID           "Wokwi-GUEST"
#define WIFI_PASSWORD       ""

#define SERIAL_DEBUG_BAUD   115200

#define LED 15
// the Wifi radio's status
int status = WL_IDLE_STATUS;

void InitWiFi()
{
  Serial.println("Connecting to AP ...");

  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) {

    delay(500);
    Serial.print(".");
  }
  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) {
      delay(500);
      Serial.print(".");
    }
    Serial.println("Connected to AP");
  }
}

void setup() {
  // initialize serial for debugging
  Serial.begin(SERIAL_DEBUG_BAUD);
  Serial.println();
  InitWiFi();
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT);
  pinMode(led8, OUTPUT);
  pinMode(led9, OUTPUT);
  pinMode(led10, OUTPUT);
  pinMode(led11, OUTPUT);
  pinMode(led12, OUTPUT);

}

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());
    digitalWrite(led12, LOW);
    digitalWrite(led1, HIGH);
    delay(500);
    digitalWrite(led1, LOW);
    digitalWrite(led2, HIGH);
    delay(500);
    digitalWrite(led2, LOW);
    digitalWrite(led3, HIGH);
    delay(500);
    digitalWrite(led3, LOW);
    digitalWrite(led4, HIGH);
    delay(500);
    digitalWrite(led4, LOW);
    digitalWrite(led5, HIGH);
    delay(500);
    digitalWrite(led5, LOW);
    digitalWrite(led6, HIGH);
    delay(500);
    digitalWrite(led6, LOW);
    digitalWrite(led7, HIGH);
    delay(500);
    digitalWrite(led7, LOW);
    digitalWrite(led8, HIGH);
    delay(500);
    digitalWrite(led8, LOW);
    digitalWrite(led9, HIGH);
    delay(500);
    digitalWrite(led9, LOW);
    digitalWrite(led10, HIGH);
    delay(500);
    digitalWrite(led10, LOW);
    digitalWrite(led11, HIGH);
    delay(500);
    digitalWrite(led11, LOW);
    digitalWrite(led12, HIGH);
    delay(500);
  }
}