Advertisement
pleasedontcode

WiFi Monitor rev_01

Sep 27th, 2024
73
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 Monitor
  13.     - Source Code NOT compiled for: Arduino Pro Mini 3.3V
  14.     - Source Code created on: 2024-09-27 21:19:00
  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 <WiFiPicker.h>  // https://github.com/Tvde1/WiFiPicker
  25. #include <ESP8266WiFi.h> // Include the ESP8266 WiFi library
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF ANALOG INPUT PINS *****/
  32. const uint8_t pot_Potentiometer_Vout_PIN_A0 = A0; // Pin for potentiometer
  33. const uint8_t battery_ADC_PIN = A0; // Using A0 for battery voltage measurement (modify if needed)
  34.  
  35. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  36. // Initialize the WiFiPicker object
  37. WiFiPicker wifiPicker;  // Create an instance of WiFiPicker
  38. Pangodream_18650_CL batteryMonitor(battery_ADC_PIN); // Create an instance of the battery monitor class
  39.  
  40. class Pangodream_18650_CL {    
  41.   public:  
  42.     Pangodream_18650_CL(int addressPin);
  43.     Pangodream_18650_CL(int addressPin, double convFactor);
  44.     Pangodream_18650_CL(int addressPin, double convFactor, int reads);
  45.     Pangodream_18650_CL();    
  46.  
  47.     int getBatteryChargeLevel();
  48.     double getBatteryVolts();
  49.     int getAnalogPin();
  50.     int pinRead();
  51.     double getConvFactor();
  52.        
  53.   private:
  54.     int    _addressPin;               //!< ADC pin used
  55.     int    _reads;                    // Number of reads of ADC pin to calculate an average value
  56.     double _convFactor;               //!< Conversion factor to translate analog units to volts
  57.     double _vs[101];                  // Array with voltage - charge definitions
  58.    
  59.     void   _initVoltsArray();
  60.     int    _getChargeLevel(double volts);
  61.     int    _analogRead(int pinNumber);
  62.     double _analogReadToVolts(int readValue);
  63. };
  64.  
  65. void setup(void)
  66. {
  67.     // put your setup code here, to run once:
  68.     Serial.begin(115200);  // Initialize serial communication at 115200 baud rate
  69.     pinMode(pot_Potentiometer_Vout_PIN_A0, INPUT);  // Set the potentiometer pin as input
  70.  
  71.     // Start the WiFiPicker service
  72.     wifiPicker.start();  // Start the WiFiPicker service
  73.  
  74.     // Print the local IP address
  75.     Serial.println(WiFi.localIP());  // Print the local IP address
  76. }
  77.  
  78. void loop(void)
  79. {
  80.     // put your main code here, to run repeatedly:
  81.     int potValue = analogRead(pot_Potentiometer_Vout_PIN_A0); // Read the potentiometer value
  82.     double potVoltage = (potValue / 1023.0) * 3.3; // Convert the analog value to voltage (assuming 3.3V reference)
  83.  
  84.     // Print the potentiometer value and voltage to the serial monitor
  85.     Serial.print("Potentiometer Value: ");
  86.     Serial.print(potValue);
  87.     Serial.print(" | Voltage: ");
  88.     Serial.println(potVoltage);
  89.  
  90.     delay(1000); // Delay for 1 second before the next reading
  91. }
  92.  
  93. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement