Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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: WiFi Button
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2024-10-01 21:29:52
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Configure WiFi and timezone settings with web page */
- /* available via both AP and STA */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <WiFi.h> // Include WiFi library for network connectivity
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- #include <Adafruit_SSD1306.h> //https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED.git
- #include <U8g2_for_Adafruit_GFX.h> //https://github.com/olikraus/U8g2_for_Adafruit_GFX
- #include "DisplayHandler.h" // Include the display handler header
- #include "EasyButtonHandler.h" // Include the EasyButton handler header
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs();
- void configureWiFi(); // Function to configure WiFi settings
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t test_PushButton_PIN_D4 = 4;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t relay_RelayModule_Signal_PIN_D13 = 13;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- bool relay_RelayModule_Signal_PIN_D13_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- float relay_RelayModule_Signal_PIN_D13_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create an EasyButton object for the button
- EasyButton button1(test_PushButton_PIN_D4); // Initialize button with pin D4
- // Create an Adafruit_SSD1306 object for the OLED display
- // The display object is now initialized in DisplayHandler.h
- // Create a U8G2_FOR_ADAFRUIT_GFX object
- U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx;
- void setup(void)
- {
- // put your setup code here, to run once:
- Serial.begin(115200); // Initialize serial communication for debugging
- pinMode(test_PushButton_PIN_D4, INPUT_PULLUP);
- pinMode(relay_RelayModule_Signal_PIN_D13, OUTPUT);
- // Initialize the button
- button1.begin();
- button1.onPressed(onButton1Pressed); // Set the callback for button press
- // Initialize the OLED display
- initializeDisplay(); // Call the display initialization function
- // Configure WiFi settings
- configureWiFi(); // Call the function to configure WiFi
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- button1.read(); // Read the button state
- }
- void updateOutputs()
- {
- digitalWrite(relay_RelayModule_Signal_PIN_D13, relay_RelayModule_Signal_PIN_D13_rawData);
- }
- // Callback function for button press
- void onButton1Pressed() {
- Serial.println("Button1 pressed"); // Print message to serial monitor
- }
- // Function to configure WiFi settings
- void configureWiFi() {
- const char* ssid = "Your_SSID"; // Replace with your WiFi SSID
- const char* password = "Your_PASSWORD"; // Replace with your WiFi password
- // Start WiFi in AP mode
- WiFi.softAP(ssid, password);
- Serial.println("Access Point started");
- // Start WiFi in STA mode
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(1000);
- Serial.println("Connecting to WiFi...");
- }
- Serial.println("Connected to WiFi");
- // Set timezone (example: GMT+0)
- configTime(0, 0, "pool.ntp.org", "time.nist.gov"); // Configure NTP server for time synchronization
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement