I am trying to take a linear damper potentiometer, lets say the value reads 200, i want it to serial print that value once until the change is large enough. Lets say it wont do anything until it sees a change of 50 bits.
The end plan is to use a 12 position rotary switch but there is a growing resistance. each position is a 1k increase in resistance. What I want is for it to only print if there is a change in the switch.
I have tried counters and a status Boolean but I cant get it to work. The base code is below, is anyone able to help?
Rotary_1 = analogRead(Rotary_1_pin);
//Serial.println(Rotary_1);
// save the current button state for comparison next time:
{
if (Rotary_1 < 100)
{
Serial.println(1);
}
else if (Rotary_1 >= 100 && Rotary_1 < 500)
{
Serial.println(2);
}
else if (Rotary_1 >= 500 && Rotary_1 < 1300)
{
Serial.println(3);
}
}
It looks like you are making things more complicated than they need to be
Before taking a new reading save the previous one to a different variable. After taking the new reading, subtract old from new and if the absolute value of the difference (use the abs() function) is greater than your delta value then do whatever you need