Advertisement
pleasedontcode

WiFi Potentiometer rev_12

Sep 27th, 2024
61
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-09-27 23:22:17
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* read and provide pot value via wifi */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <SPI.h>  // Include SPI library for communication with the WiFi module
  25. #include <WiFi.h> // Include WiFi library for WiFi functionality
  26. #include "keys.h"  // Include the keys.h file for WiFi credentials
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF ANALOG INPUT PINS *****/
  33. const uint8_t pot_Potentiometer_Vout_PIN_A0 = A0;  // Define the analog pin for the potentiometer
  34.  
  35. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  36. const char* ssid = WIFI_SSID;  // WiFi SSID from keys.h
  37. const char* password = WIFI_PASSWORD;  // WiFi Password from keys.h
  38.  
  39. void setup(void)
  40. {
  41.     // Initialize serial communication
  42.     Serial.begin(115200);
  43.    
  44.     // Connect to WiFi
  45.     WiFi.begin(ssid, password);
  46.     Serial.println("Connecting to WiFi...");
  47.    
  48.     // Wait for connection
  49.     while (WiFi.status() != WL_CONNECTED) {
  50.         delay(1000);
  51.         Serial.println("Connecting...");
  52.     }
  53.    
  54.     Serial.println("Connected to WiFi");
  55.    
  56.     // Set the potentiometer pin as input
  57.     pinMode(pot_Potentiometer_Vout_PIN_A0, INPUT);
  58. }
  59.  
  60. void loop(void)
  61. {
  62.     // Read the potentiometer value
  63.     int potValue = analogRead(pot_Potentiometer_Vout_PIN_A0);  // Read the analog value from the potentiometer
  64.    
  65.     // Print the potentiometer value to the serial monitor
  66.     Serial.print("Potentiometer Value: ");
  67.     Serial.println(potValue);
  68.    
  69.     // Add a small delay to avoid flooding the serial output
  70.     delay(1000);  // Delay for 1 second
  71. }
  72.  
  73. /****** DEFINITION OF CREDENTIALS IN keys.h *****/
  74. #ifndef KEYS_H
  75. #define KEYS_H
  76.  
  77. // Define WiFi credentials
  78. extern const char* WIFI_SSID;     // WiFi SSID
  79. extern const char* WIFI_PASSWORD;  // WiFi Password
  80. extern const char* DEVICE_ID;      // Device ID
  81. extern const char* DEVICE_TOKEN;   // Device Token
  82.  
  83. #endif  // KEYS_H
  84.  
  85. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement