Advertisement
pleasedontcode

WiFi LED Toggle rev_01

Sep 29th, 2024
79
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: WiFi LED Toggle
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-09-29 15:43:25
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* wifi kapcsolatot szeretnék ami egy ledet kapol be */
  21.     /* és ki. */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <WiFi.h> // Include the WiFi library for ESP32
  26. #include <WiFiClient.h> // Include the WiFiClient library for handling client connections
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31. void updateOutputs(void);
  32.  
  33. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  34. const uint8_t led_LED_PIN_D4 = 4; // Define the pin for the LED
  35.  
  36. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  37. /***** used to store raw data *****/
  38. bool led_LED_PIN_D4_rawData = false; // Initialize the LED state (off)
  39.  
  40. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  41. /***** used to store data after characteristic curve transformation *****/
  42. float led_LED_PIN_D4_phyData = 0.0; // Placeholder for physical data (not used in this example)
  43.  
  44. // WiFi credentials
  45. const char* ssid = "YourWiFiSSID"; // Replace with your WiFi SSID
  46. const char* password = "YourWiFiPassword"; // Replace with your WiFi password
  47.  
  48. void setup(void)
  49. {
  50.     // Initialize serial communication for debugging
  51.     Serial.begin(115200);
  52.    
  53.     // Connect to WiFi
  54.     WiFi.begin(ssid, password);
  55.     Serial.print("Connecting to WiFi");
  56.    
  57.     // Wait for connection
  58.     while (WiFi.status() != WL_CONNECTED) {
  59.         delay(500);
  60.         Serial.print(".");
  61.     }
  62.    
  63.     Serial.println("Connected to WiFi");
  64.    
  65.     // Set the LED pin as output
  66.     pinMode(led_LED_PIN_D4, OUTPUT);
  67. }
  68.  
  69. void loop(void)
  70. {
  71.     // Refresh output data
  72.     updateOutputs();
  73.  
  74.     // Check WiFi connection status
  75.     if (WiFi.status() == WL_CONNECTED) {
  76.         led_LED_PIN_D4_rawData = !led_LED_PIN_D4_rawData; // Toggle LED state
  77.         delay(1000); // Wait for 1 second before toggling again
  78.     }
  79. }
  80.  
  81. void updateOutputs()
  82. {
  83.     digitalWrite(led_LED_PIN_D4, led_LED_PIN_D4_rawData); // Update the LED state
  84. }
  85.  
  86. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement