/********* Pleasedontcode.com **********

	Pleasedontcode thanks you for automatic code generation! Enjoy your code!

	- Terms and Conditions:
	You have a non-exclusive, revocable, worldwide, royalty-free license
	for personal and commercial use. Attribution is optional; modifications
	are allowed, but you're responsible for code maintenance. We're not
	liable for any loss or damage. For full terms,
	please visit pleasedontcode.com/termsandconditions.

	- Project: "Button Connectivity"
	- Source Code NOT compiled for: ESP32 DevKit V1
	- Source Code created on: 2024-06-06 16:31:46

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* Turn on 6 light from wifi */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include <EasyButton.h>  //https://github.com/evert-arias/EasyButton
#include <WiFi.h>        // Include the WiFi library

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void onButtonPressed();

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t San_PushButton_PIN_D4 = 4;

/****** DEFINITION OF DIGITAL OUTPUT PINS FOR LIGHTS *****/
const uint8_t Light_PIN_1 = 5;
const uint8_t Light_PIN_2 = 18;
const uint8_t Light_PIN_3 = 19;
const uint8_t Light_PIN_4 = 21;
const uint8_t Light_PIN_5 = 22;
const uint8_t Light_PIN_6 = 23;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
EasyButton button(San_PushButton_PIN_D4);  // Initialize EasyButton object with the pin

/****** WIFI CREDENTIALS *****/
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";

void onButtonPressed() {
  Serial.println("Button pressed");

  // Toggle the state of the lights
  digitalWrite(Light_PIN_1, !digitalRead(Light_PIN_1));
  digitalWrite(Light_PIN_2, !digitalRead(Light_PIN_2));
  digitalWrite(Light_PIN_3, !digitalRead(Light_PIN_3));
  digitalWrite(Light_PIN_4, !digitalRead(Light_PIN_4));
  digitalWrite(Light_PIN_5, !digitalRead(Light_PIN_5));
  digitalWrite(Light_PIN_6, !digitalRead(Light_PIN_6));
}

void setup(void) {
  // Initialize serial communication
  Serial.begin(115200);
  Serial.println();
  Serial.println(">>> EasyButton single button example <<<");

  // Initialize the button
  button.begin();
  button.onPressed(onButtonPressed);

  // Initialize the light pins as outputs
  pinMode(Light_PIN_1, OUTPUT);
  pinMode(Light_PIN_2, OUTPUT);
  pinMode(Light_PIN_3, OUTPUT);
  pinMode(Light_PIN_4, OUTPUT);
  pinMode(Light_PIN_5, OUTPUT);
  pinMode(Light_PIN_6, OUTPUT);

  // Initialize the lights to be off
  digitalWrite(Light_PIN_1, LOW);
  digitalWrite(Light_PIN_2, LOW);
  digitalWrite(Light_PIN_3, LOW);
  digitalWrite(Light_PIN_4, LOW);
  digitalWrite(Light_PIN_5, LOW);
  digitalWrite(Light_PIN_6, LOW);

  // Connect to WiFi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");
}

void loop(void) {
  // Continuously read the status of the button
  button.read();
}

/* END CODE */