const int analogPin = 34;  // Analog pin connected to the variable resistor
const int currentSensePin = 35;  // Analog pin connected to the current sensing resistor
const float referenceVoltage = 3.3;  // Reference voltage of the ESP32

void setup() {
  Serial.begin(115200);
}

void loop() {
  // Read analog values
  int analogValue = analogRead(analogPin);           // Read voltage from variable resistor
  int currentSenseValue = analogRead(currentSensePin); // Read voltage from current sensing resistor

  // Convert analog values to physical quantities
  float voltage = analogValue * referenceVoltage / 4095.0;  // Convert analog value to voltage (12-bit ADC)
  float current = currentSenseValue * referenceVoltage / 4095.0; // Convert analog value to current

  // Calculate power and resistor values
  float power = voltage * current;
  float resistor = voltage / current;

  // Increment the counter with each loop iteration
  static int counter = 0;
  counter++;

  // Create a string with comma-separated values, including the counter
  String outputString = "Mesurment No." + String(counter) + "," + String(voltage) + " V," + String(current) + " A," + String(power) + " W," + String(resistor) + " ohms";

  // Print the string to the serial monitor
  Serial.println(outputString);

  delay(1000);  // You can adjust the delay based on your needs
}