/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: WiFi Monitor
- Source Code NOT compiled for: Arduino Pro Mini 3.3V
- Source Code created on: 2024-09-27 21:19:00
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* read and provide pot value via wifi */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include // https://github.com/Tvde1/WiFiPicker
#include // Include the ESP8266 WiFi library
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
/***** DEFINITION OF ANALOG INPUT PINS *****/
const uint8_t pot_Potentiometer_Vout_PIN_A0 = A0; // Pin for potentiometer
const uint8_t battery_ADC_PIN = A0; // Using A0 for battery voltage measurement (modify if needed)
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
// Initialize the WiFiPicker object
WiFiPicker wifiPicker; // Create an instance of WiFiPicker
Pangodream_18650_CL batteryMonitor(battery_ADC_PIN); // Create an instance of the battery monitor class
class Pangodream_18650_CL {
public:
Pangodream_18650_CL(int addressPin);
Pangodream_18650_CL(int addressPin, double convFactor);
Pangodream_18650_CL(int addressPin, double convFactor, int reads);
Pangodream_18650_CL();
int getBatteryChargeLevel();
double getBatteryVolts();
int getAnalogPin();
int pinRead();
double getConvFactor();
private:
int _addressPin; //!< ADC pin used
int _reads; // Number of reads of ADC pin to calculate an average value
double _convFactor; //!< Conversion factor to translate analog units to volts
double _vs[101]; // Array with voltage - charge definitions
void _initVoltsArray();
int _getChargeLevel(double volts);
int _analogRead(int pinNumber);
double _analogReadToVolts(int readValue);
};
void setup(void)
{
// put your setup code here, to run once:
Serial.begin(115200); // Initialize serial communication at 115200 baud rate
pinMode(pot_Potentiometer_Vout_PIN_A0, INPUT); // Set the potentiometer pin as input
// Start the WiFiPicker service
wifiPicker.start(); // Start the WiFiPicker service
// Print the local IP address
Serial.println(WiFi.localIP()); // Print the local IP address
}
void loop(void)
{
// put your main code here, to run repeatedly:
int potValue = analogRead(pot_Potentiometer_Vout_PIN_A0); // Read the potentiometer value
double potVoltage = (potValue / 1023.0) * 3.3; // Convert the analog value to voltage (assuming 3.3V reference)
// Print the potentiometer value and voltage to the serial monitor
Serial.print("Potentiometer Value: ");
Serial.print(potValue);
Serial.print(" | Voltage: ");
Serial.println(potVoltage);
delay(1000); // Delay for 1 second before the next reading
}
/* END CODE */