Hi All,
I'm trying to read potentiometer values and to use millis() for no blocking delay. Everything works fine until potentiometer value goes over ~305.
Can anybody please help me figure out what is the problem that suddenly calculation result gets wrong when potentiometer value reaches certain level.
Code:
unsigned long time_now = 0;
int potValue = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
potValue = analogRead(A2);
if(millis() > time_now + (100 * potValue)){
time_now = millis();
Serial.println("..................");
Serial.println(time_now);
Serial.println(potValue);
Serial.println(time_now + (100 * potValue));
Serial.println("..................");
}
}
Results:
..................
14557
68
21357
..................
..................
21372
68
28172
..................
..................
38962
175
56462
..................
..................
69329
303
99629
..................
..................
71432
328
38696
..................
..................
71434
328
38698
..................