Advertisement
pleasedontcode

"Wi-Fi Blink" rev_01

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