Hi,
I'm writing a code for a potentiometer to convert the voltage it reads to degrees. Now, everything was going swimmingly until I used the line equation to calculate degrees. The potentiometer I have turns from about 240 degrees to -60 (I used some electrical tape to make a flag so I could measure that more easily.)
The voltage is reading just fine from 0 to 1023, but when I try to get degrees it prints -60. I've tried a few variations, but the equation just isn't getting the right value.
int potPin = 2;
float val;
float temp;
float temp2;
float deg;
void setup() {
Serial.begin(9600);
getVolt();
}
void loop() {
if (abs(getVolt()-temp) > 2){
temp = val;
Serial.println(val);
deg = val*(100/341)-60;
Serial.println(deg);
Serial.print(" degrees.");
}
else{
}
}
float getVolt(){
val = analogRead(potPin);
return val;
}