Slow encoder response

Hello,
I read the analog input and compare it to a value that I want. I also use hysteresis and delay to run two pwm controlled motors. When I run the program below, everything works fine if I turn the encoder slowly, any value is left in any of its output when I turn the encoder a little fast. Is the logic in the program completely wrong?

test_9_2_wo_led_4.txt (7.39 KB)

I didn't look deeply but there are quite a few of these:

    else
    {
      coldout == 0;
    }

Try setting IDE->file/preferences/compiler warnings to All.

Whoops - dangling elses everywhere - very confusing and definitely bad style:

This is a dangling-else:

if (cond1)
  if (cond2)
    foo();
  else
    bar();

Which if is the else meant to correspond to?

What if I wrote it:

if (cond1)
  if (cond2)
    foo();
else
  bar();

The compiler sees these the same, whereas a human might see them different.

So always use braces when nesting if-elses:

if (cond1)
{
  if (cond2)
    foo();
}
else
  bar();

or

if (cond1)
{
  if (cond2)
    foo();
  else
    bar();
}

Then the intention is unambiguous. Remember that the indentation is completely
ignored by the language & compiler in C.

In fact there's an argument to always use braces for the then and else parts of a
conditional statement, although this is perhaps overkill.

BTW your encoder code is way over-complex, encoders do not need and shouldn't be
given debouncing logic, as they self-correct due to the nature of quadrature signals.