int potential = A0; //A0 is a HEXADECIMAL number
int potValue;
void setup() {
pinMode(potential, INPUT);
Serial.begin(9600); // Setting baud rate to 9600 bits per second
}
void loop() {
potValue = analogRead(potential);
Serial.println(potValue);
}
What I'm trying to do is:
if the value of potentiometer =1023,
it will print only once in the serial monitor until the value is changed.
You need a variable.
Compare the new value with that variable, to detect if something has changed.
Then store the new value in that variable for the next time.
You can name it: "oldPotValue" or "previousPotValue", or just "oldValue".
Then use a if-statement:
potValue = analogRead(potPin);
if( potValue != oldPotValue)
{
Serial.println("Something has changed");
oldPotValue = potValue; // remember for the next time
}
I tried this and it doesn't work? It does print the "Something has changed" but it keeps repeating the value of the potentiometer on top of "Something has changed" I'm looking for it to only print the value one time, and when the value changes, it prints the current value only once.
If the potentiometer is stationary, the ADC count may vary slightly due to noise.
You might want to check that it doesn't change by more than some threshold, before you print the new value.