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

#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(".");
    digitalWrite(25, HIGH);
  delay(25);
  digitalWrite(25, LOW);
  digitalWrite(33, HIGH);
  delay(25);
  digitalWrite(33, LOW);
  digitalWrite(32, HIGH);
  delay(25);
  digitalWrite(32, LOW);
  digitalWrite(23, HIGH);
  delay(25);
  digitalWrite(23, LOW);
  digitalWrite(22, HIGH);
  delay(25);
  digitalWrite(22, LOW);
  digitalWrite(21, HIGH);
  delay(25);
  digitalWrite(21, LOW);
  digitalWrite(19, HIGH);
  delay(25);
  digitalWrite(19, LOW);
  digitalWrite(18, HIGH);
  delay(25);
  digitalWrite(18, LOW);
  digitalWrite(5, HIGH);
  delay(25);
  digitalWrite(5, LOW);
  digitalWrite(4, HIGH);
  delay(25);
  digitalWrite(4, LOW);
  digitalWrite(2, HIGH);
  delay(25);
  digitalWrite(2, LOW);
  digitalWrite(15, HIGH);
  delay(25);
  digitalWrite(15, LOW);
  }
  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() {
  // put your setup code here, to run once:
  // initialize serial for debugging
  pinMode(LED, OUTPUT);
  pinMode(25, OUTPUT);
  pinMode(33, OUTPUT);
  pinMode(32, OUTPUT);
  pinMode(23, OUTPUT);
  pinMode(22, OUTPUT);
  pinMode(21, OUTPUT);
  pinMode(19, OUTPUT);
  pinMode(18, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(15, OUTPUT);
  Serial.begin(SERIAL_DEBUG_BAUD);
  Serial.println();
  InitWiFi();
} 

void loop() {
  // put your main code here, to run repeatedly:
  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(LED, HIGH);
    delay(200);
    digitalWrite(LED, LOW);
  }
  digitalWrite(25, HIGH);
  delay(1000);
  digitalWrite(25, LOW);
  digitalWrite(33, HIGH);
  delay(1000);
  digitalWrite(33, LOW);
  digitalWrite(32, HIGH);
  delay(1000);
  digitalWrite(32, LOW);
  digitalWrite(23, HIGH);
  delay(1000);
  digitalWrite(23, LOW);
  digitalWrite(22, HIGH);
  delay(1000);
  digitalWrite(22, LOW);
  digitalWrite(21, HIGH);
  delay(1000);
  digitalWrite(21, LOW);
  digitalWrite(19, HIGH);
  delay(1000);
  digitalWrite(19, LOW);
  digitalWrite(18, HIGH);
  delay(1000);
  digitalWrite(18, LOW);
  digitalWrite(5, HIGH);
  delay(1000);
  digitalWrite(5, LOW);
  digitalWrite(4, HIGH);
  delay(1000);
  digitalWrite(4, LOW);
  digitalWrite(2, HIGH);
  delay(1000);
  digitalWrite(2, LOW);
  digitalWrite(15, HIGH);
  delay(1000);
  digitalWrite(15, LOW);
}