/**
 * Auteur : Anatole SCHRAMM-HENRY
 * Date : 11/11/2019
 * Programme de test permettant de se familiariser avec les différentes formules U=R*I
 */
#include <math.h>
#define V_STEP 0.000805860 //Volt 3.3/(4096-1)
const double R_PREC(1471.0); //Ohm

unsigned int Raw(0.0);
double Vref(0.0);
double Iref(0.0);
double Rvar(0.0);
char buffer[300];



void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(PA0, INPUT);
}

void loop() {
  Raw = analogRead(PA0);
  Vref = rawToVref(Raw); //En Volt
  Iref = Vref / R_PREC;  //En Ampère

  Rvar = (3.3-Vref)/Iref;
  // put your main code here, to run repeatedly:
  Serial.println("------------------------------------");
  sprintf(buffer, "%d",Raw);
  Serial.print("Raw : ");Serial.println(buffer);
  
  sprintf(buffer, "%.6f Volts",Vref);
  Serial.print("Voltage : ");Serial.println(buffer);
  
  sprintf(buffer, "%.6f Amperes -> %.6f mA",Iref, Iref*1000.0);
  Serial.print("Current : ");Serial.println(buffer);
  
  sprintf(buffer, "%.6f Ohm",Rvar);
  Serial.print("Resistance : ");Serial.println(buffer);
  
  Serial.println("------------------------------------");
  delay(1000);
}

float rawToVref(float raw)
{
  return V_STEP * (float)Raw;
}
