Advertisement
pleasedontcode

WiFi Potentiometer rev_47

Oct 1st, 2024
76
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 Potentiometer
  13.     - Source Code compiled for: Arduino Pro Mini 3.3V
  14.     - Source Code created on: 2024-10-01 21:15:06
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* read and provide pot value via wifi */
  21. /****** SYSTEM REQUIREMENT 2 *****/
  22.     /* if main code is too long so split code in other */
  23.     /* files. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <WiFi.h>
  28. #include "WiFiConfig.h"
  29. #include "PotentiometerReader.h"
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF ANALOG INPUT PINS *****/
  36. const uint8_t pot_Potentiometer_Vout_PIN_A0 = A0;
  37.  
  38. // WiFi connection status variable
  39. bool wifiConnected = false;
  40.  
  41. void setup(void)
  42. {
  43.     // Initialize serial communication for debugging
  44.     Serial.begin(115200);
  45.    
  46.     // Connect to WiFi
  47.     WiFi.begin(ssid, password);
  48.     while (WiFi.status() != WL_CONNECTED) {
  49.         delay(1000);
  50.         Serial.println("Connecting to WiFi...");
  51.     }
  52.     Serial.println("Connected to WiFi");
  53.     wifiConnected = true; // Update connection status
  54.    
  55.     // Set the potentiometer pin as input
  56.     pinMode(pot_Potentiometer_Vout_PIN_A0, INPUT);
  57. }
  58.  
  59. void loop(void)
  60. {
  61.     // Check if WiFi is connected before reading the potentiometer
  62.     if (wifiConnected) {
  63.         // Read the potentiometer value
  64.         int potValue = readPotentiometer(pot_Potentiometer_Vout_PIN_A0);
  65.        
  66.         // Print the potentiometer value to the serial monitor
  67.         Serial.print("Potentiometer Value: ");
  68.         Serial.println(potValue);
  69.        
  70.         // Delay for a short period before the next reading
  71.         delay(1000);
  72.     }
  73. }
  74.  
  75. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement