Arduino Diecimila (ATmega168), IDE 1.6.1
I have a pot connected to 5 volts, ground, and analog pin 0. I read the pin each time through the loop and test the value to see if it's changed. If outside +/-2, I print it to the computer screen.
As I turn the pot slowly I can't get to value 0; it stops about 50. If I turn quickly I can get to 0, or close.
I measured the pin and it goes all the way to 0 volts with the pot turned all the way.
I modified the code to not test Speed value, only to print the value as I turn the pot. It prints full range all the way to 0.
It is the limits testing that is causing the problem with the full range of values of Speed.
Why?
Thanks for any help.
Cheers.
int analogPin = 0;
int Speed = 0;
int OldSpeed = 0;
void setup() {
analogReference(DEFAULT);
Serial.begin(9600); // send and receive at 9600 baud
}
void loop() {
Speed = analogRead(analogPin); // fetch pot value
// if (Speed != OldSpeed) {
if ((Speed < OldSpeed-2) || // hysteresis
( Speed > OldSpeed+2)) { // hysteresis
Serial.print("Speed is "); // if it's changed tell me
Serial.println(Speed); // send end of line ch
}
OldSpeed = Speed;
}