Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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: Battery Monitor
- - Source Code compiled for: Arduino Pro Mini 3.3V
- - Source Code created on: 2024-09-27 22:59:14
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* read and provide pot value via wifi */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- // Removed WiFiPicker as it is not compatible with Arduino Pro Mini 3.3V
- /*
- * 18650 Ion-Li battery charge
- */
- #ifndef Pangodream_18650_CL_h
- #define Pangodream_18650_CL_h
- #include "Arduino.h"
- #define DEF_PIN 34 // GPIO34 is not available on Arduino Pro Mini 3.3V
- #define DEF_CONV_FACTOR 1.7
- #define DEF_READS 20
- /*
- * 18650 Ion-Li battery charge
- * Calculates charge level of an 18650 Ion-Li battery
- */
- class Pangodream_18650_CL {
- public:
- /*
- * Constructor
- * @param addressPin, ADC pin number where the voltage divider is connected to
- */
- Pangodream_18650_CL(int addressPin);
- /*
- * Constructor
- * @param addressPin, ADC pin number where the voltage divider is connected to
- * @param convFactor, Convertion factor for analog read units to volts
- */
- Pangodream_18650_CL(int addressPin, double convFactor);
- /*
- * Constructor
- * @param addressPin, ADC pin number where the voltage divider is connected to
- * @param convFactor, Convertion factor for analog read units to volts
- * @param reads, Number of reads of analog pin to calculate an average value
- */
- Pangodream_18650_CL(int addressPin, double convFactor, int reads);
- /*
- * Constructor
- */
- Pangodream_18650_CL();
- /*
- * Get the battery charge level (0-100)
- * @return The calculated battery charge level
- */
- int getBatteryChargeLevel();
- double getBatteryVolts();
- int getAnalogPin();
- int pinRead();
- double getConvFactor();
- private:
- int _addressPin; //!< ADC pin used, default is GPIO34 - ADC1_6
- int _reads; // Number of reads of ADC pin to calculate an average value
- double _convFactor; //!< Convertion 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);
- };
- #endif
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF ANALOG INPUT PINS *****/
- const uint8_t pot_Potentiometer_Vout_PIN_A0 = A0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
- // No WiFiPicker instance as it is not compatible with Arduino Pro Mini 3.3V
- void setup(void)
- {
- // Initialize serial communication
- Serial.begin(115200);
- // Print a message indicating that the setup is complete
- Serial.println("Setup complete. No WiFi functionality available.");
- // Set the potentiometer pin as input
- pinMode(pot_Potentiometer_Vout_PIN_A0, INPUT);
- }
- void loop(void)
- {
- // Read the potentiometer value
- int potValue = analogRead(pot_Potentiometer_Vout_PIN_A0); // Read the analog value from the potentiometer
- // Print the potentiometer value to the serial monitor
- Serial.print("Potentiometer Value: ");
- Serial.println(potValue);
- // Add a small delay to avoid flooding the serial output
- delay(1000); // Delay for 1 second
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement