#define VOLTAGE_PIN 34 // Pin para el potenciómetro de voltaje
#define CURRENT_PIN 35 // Pin para el potenciómetro de corriente
void setup() {
Serial.begin(115200); // Inicializar la comunicación serie
pinMode(VOLTAGE_PIN, INPUT);
pinMode(CURRENT_PIN, INPUT);
}
void loop() {
// Leer los valores de los potenciómetros
int voltageRaw = analogRead(VOLTAGE_PIN);
int currentRaw = analogRead(CURRENT_PIN);
// Convertir los valores leídos a voltaje y corriente
float voltage = (voltageRaw / 4095.0) * 240.0; // 0-240 VDC
float current = (currentRaw / 4095.0) * 100.0; // 0-100 ADC
// Calcular resistencia y potencia
float resistance = (current != 0) ? (voltage / current) : 0; // Evitar división por cero
float power = voltage * current;
// Imprimir los valores en el puerto serie
Serial.print("Voltaje: ");
Serial.print(voltage);
Serial.println(" V");
Serial.print("Corriente: ");
Serial.print(current);
Serial.println(" A");
Serial.print("Resistencia: ");
Serial.print(resistance);
Serial.println(" ohms");
Serial.print("Potencia: ");
Serial.print(power);
Serial.println(" W");
delay(1000); // Esperar 1 segundo antes de la siguiente lectura
}