Advertisement
pleasedontcode

"Wi-Fi LED" rev_02

Jun 11th, 2024
329
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: "Wi-Fi LED"
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-06-11 14:24:29
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* ESP32 code LED blinking in specific patterns to */
  21.     /* two ESP32 devices. Red, Blue, Green and Yellow LED */
  22.     /* blinking in a pre-programmed delays. Add Firebase */
  23.     /* integration for web hosting, authentication and */
  24.     /* using realtime database. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <WiFi.h>
  30. #include <FirebaseESP32.h>  //https://github.com/mobizt/Firebase-ESP32
  31. #include <addons/TokenHelper.h>  // Provide the token generation process info.
  32. #include <addons/RTDBHelper.h>  // Provide an RTDB helper functions.
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37. void updateOutputs(void);
  38. void blinkPattern(void);
  39.  
  40. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  41. const uint8_t GPIO23_LED_PIN_D4 = 4;
  42. const uint8_t GPIO22_LED_PIN_D13 = 13;
  43. const uint8_t GPIO21_LED_PIN_D14 = 14;
  44. const uint8_t GPIO19_LED_PIN_D16 = 16;
  45.  
  46. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  47. /***** used to store raw data *****/
  48. bool GPIO23_LED_PIN_D4_rawData = 0;
  49. bool GPIO22_LED_PIN_D13_rawData = 0;
  50. bool GPIO21_LED_PIN_D14_rawData = 0;
  51. bool GPIO19_LED_PIN_D16_rawData = 0;
  52.  
  53. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  54. /***** used to store data after characteristic curve transformation *****/
  55. float GPIO23_LED_PIN_D4_phyData = 0.0;
  56. float GPIO22_LED_PIN_D13_phyData = 0.0;
  57. float GPIO21_LED_PIN_D14_phyData = 0.0;
  58. float GPIO19_LED_PIN_D16_phyData = 0.0;
  59.  
  60. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  61.  
  62. // Define Firebase Data object
  63. FirebaseData fbdo;
  64.  
  65. // Define the FirebaseAuth data for authentication data
  66. FirebaseAuth auth;
  67.  
  68. // Define the FirebaseConfig data for config data
  69. FirebaseConfig config;
  70.  
  71. // WiFi credentials
  72. #define WIFI_SSID "your_wifi_ssid"
  73. #define WIFI_PASSWORD "your_wifi_password"
  74.  
  75. // Firebase project API Key
  76. #define API_KEY "your_firebase_api_key"
  77.  
  78. // Firebase project URL
  79. #define DATABASE_URL "your_firebase_database_url"
  80.  
  81. // User credentials
  82. #define USER_EMAIL "your_email"
  83. #define USER_PASSWORD "your_password"
  84.  
  85. void setup(void)
  86. {
  87.     // put your setup code here, to run once:
  88.     Serial.begin(115200);
  89.  
  90.     // Connect to Wi-Fi
  91.     WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  92.     Serial.print("Connecting to Wi-Fi");
  93.     while (WiFi.status() != WL_CONNECTED)
  94.     {
  95.         Serial.print(".");
  96.         delay(300);
  97.     }
  98.     Serial.println();
  99.     Serial.print("Connected with IP: ");
  100.     Serial.println(WiFi.localIP());
  101.     Serial.println();
  102.  
  103.     // Assign the api key (required)
  104.     config.api_key = API_KEY;
  105.  
  106.     // Assign the user sign in credentials
  107.     auth.user.email = USER_EMAIL;
  108.     auth.user.password = USER_PASSWORD;
  109.  
  110.     // Assign the RTDB URL (required)
  111.     config.database_url = DATABASE_URL;
  112.  
  113.     // Assign the callback function for the long running token generation task
  114.     config.token_status_callback = tokenStatusCallback; // see addons/TokenHelper.h
  115.  
  116.     // Initialize the library with the Firebase authen and config.
  117.     Firebase.begin(&config, &auth);
  118.  
  119.     // Optional, set AP reconnection in setup()
  120.     Firebase.reconnectWiFi(true);
  121.  
  122.     pinMode(GPIO23_LED_PIN_D4, OUTPUT);
  123.     pinMode(GPIO22_LED_PIN_D13, OUTPUT);
  124.     pinMode(GPIO21_LED_PIN_D14, OUTPUT);
  125.     pinMode(GPIO19_LED_PIN_D16, OUTPUT);
  126. }
  127.  
  128. void loop(void)
  129. {
  130.     // put your main code here, to run repeatedly:
  131.     updateOutputs(); // Refresh output data
  132.     blinkPattern();  // Execute LED blinking pattern
  133. }
  134.  
  135. void updateOutputs()
  136. {
  137.     digitalWrite(GPIO23_LED_PIN_D4, GPIO23_LED_PIN_D4_rawData);
  138.     digitalWrite(GPIO22_LED_PIN_D13, GPIO22_LED_PIN_D13_rawData);
  139.     digitalWrite(GPIO21_LED_PIN_D14, GPIO21_LED_PIN_D14_rawData);
  140.     digitalWrite(GPIO19_LED_PIN_D16, GPIO19_LED_PIN_D16_rawData);
  141. }
  142.  
  143. void blinkPattern()
  144. {
  145.     // Example blinking pattern
  146.     GPIO23_LED_PIN_D4_rawData = HIGH;
  147.     updateOutputs();
  148.     delay(500);
  149.     GPIO23_LED_PIN_D4_rawData = LOW;
  150.     updateOutputs();
  151.     delay(500);
  152.  
  153.     GPIO22_LED_PIN_D13_rawData = HIGH;
  154.     updateOutputs();
  155.     delay(500);
  156.     GPIO22_LED_PIN_D13_rawData = LOW;
  157.     updateOutputs();
  158.     delay(500);
  159.  
  160.     GPIO21_LED_PIN_D14_rawData = HIGH;
  161.     updateOutputs();
  162.     delay(500);
  163.     GPIO21_LED_PIN_D14_rawData = LOW;
  164.     updateOutputs();
  165.     delay(500);
  166.  
  167.     GPIO19_LED_PIN_D16_rawData = HIGH;
  168.     updateOutputs();
  169.     delay(500);
  170.     GPIO19_LED_PIN_D16_rawData = LOW;
  171.     updateOutputs();
  172.     delay(500);
  173. }
  174.  
  175. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement