int analogPin = A0; // potentiometer wiper (middle terminal) connected to analog pin 3
// outside leads to ground and +5V
float val = 0; // variable to store the value read
float distancia;
float tensao;
float incerteza;
float timestamp = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // setup serial
Serial.println("timestamp, medida, incerteza");
}
void loop() {
// put your main code here, to run repeatedly:
val = analogRead(analogPin); // read the input pin
val = map(val, 0, 1023, 314, 891); // scale it to use it with the servo (value between 0 and 180)
//Serial.println(val);
tensao = val*5/1024;
//Serial.println(tensao);
distancia = -1.4968*tensao*tensao + 12.874*tensao - 15.835;
incerteza = distancia * 0.05;
Serial.print(timestamp); // debug value
Serial.print(",");
Serial.print(distancia);
Serial.print(",");
Serial.println(incerteza);
timestamp = timestamp + 0.2;
delay(200); // faz 5 vezes por segundo
}