One obvious problem is that you are returning the address to a local variable:
int *readPot() ///read potentiometer value
{
int tempValue = analogRead(A0);
int *potValue = &tempValue;
return potValue;
}
Here, the returned pointer points to the address of tempValue
. This ceases to be valid once the function returns. Just use an int
:
int readPot() ///read potentiometer value
{
return analogRead(A0);
}
Next, I doubt that this is a valid argument to Serial.println
:
Serial.println("Potentiometer reading:" + *potValue);
but this should work:
int potValue = readPot();
Serial.print("Potentiometer reading: ");
Serial.println(potValue);