Advertisement
pleasedontcode

"Button Connectivity" rev_01

Jun 6th, 2024
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Button Connectivity"
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-06-06 16:31:46
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Turn on 6 light from wifi */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <EasyButton.h>  //https://github.com/evert-arias/EasyButton
  25. #include <WiFi.h>        // Include the WiFi library
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30. void onButtonPressed();
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t San_PushButton_PIN_D4 = 4;
  34.  
  35. /****** DEFINITION OF DIGITAL OUTPUT PINS FOR LIGHTS *****/
  36. const uint8_t Light_PIN_1 = 5;
  37. const uint8_t Light_PIN_2 = 18;
  38. const uint8_t Light_PIN_3 = 19;
  39. const uint8_t Light_PIN_4 = 21;
  40. const uint8_t Light_PIN_5 = 22;
  41. const uint8_t Light_PIN_6 = 23;
  42.  
  43. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  44. EasyButton button(San_PushButton_PIN_D4);  // Initialize EasyButton object with the pin
  45.  
  46. /****** WIFI CREDENTIALS *****/
  47. const char* ssid = "your_SSID";
  48. const char* password = "your_PASSWORD";
  49.  
  50. void onButtonPressed() {
  51.   Serial.println("Button pressed");
  52.  
  53.   // Toggle the state of the lights
  54.   digitalWrite(Light_PIN_1, !digitalRead(Light_PIN_1));
  55.   digitalWrite(Light_PIN_2, !digitalRead(Light_PIN_2));
  56.   digitalWrite(Light_PIN_3, !digitalRead(Light_PIN_3));
  57.   digitalWrite(Light_PIN_4, !digitalRead(Light_PIN_4));
  58.   digitalWrite(Light_PIN_5, !digitalRead(Light_PIN_5));
  59.   digitalWrite(Light_PIN_6, !digitalRead(Light_PIN_6));
  60. }
  61.  
  62. void setup(void) {
  63.   // Initialize serial communication
  64.   Serial.begin(115200);
  65.   Serial.println();
  66.   Serial.println(">>> EasyButton single button example <<<");
  67.  
  68.   // Initialize the button
  69.   button.begin();
  70.   button.onPressed(onButtonPressed);
  71.  
  72.   // Initialize the light pins as outputs
  73.   pinMode(Light_PIN_1, OUTPUT);
  74.   pinMode(Light_PIN_2, OUTPUT);
  75.   pinMode(Light_PIN_3, OUTPUT);
  76.   pinMode(Light_PIN_4, OUTPUT);
  77.   pinMode(Light_PIN_5, OUTPUT);
  78.   pinMode(Light_PIN_6, OUTPUT);
  79.  
  80.   // Initialize the lights to be off
  81.   digitalWrite(Light_PIN_1, LOW);
  82.   digitalWrite(Light_PIN_2, LOW);
  83.   digitalWrite(Light_PIN_3, LOW);
  84.   digitalWrite(Light_PIN_4, LOW);
  85.   digitalWrite(Light_PIN_5, LOW);
  86.   digitalWrite(Light_PIN_6, LOW);
  87.  
  88.   // Connect to WiFi
  89.   WiFi.begin(ssid, password);
  90.   while (WiFi.status() != WL_CONNECTED) {
  91.     delay(1000);
  92.     Serial.println("Connecting to WiFi...");
  93.   }
  94.   Serial.println("Connected to WiFi");
  95. }
  96.  
  97. void loop(void) {
  98.   // Continuously read the status of the button
  99.   button.read();
  100. }
  101.  
  102. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement