Help with signal conditioning

dhenry:
Alternatively, you can introduce some derivative gain, similar to a PID controller, for this.

I find your suggestion interesting.
I found that:

While the math is way above my head, in the bottom they put a simple pseudocode, which they said is suited for MCUs:

previous_error = 0
integral = 0 
start:
  error = setpoint - measured_value
  integral = integral + error*dt
  derivative = (error - previous_error)/dt
  output = Kp*error + Ki*integral + Kd*derivative
  previous_error = error
  wait(dt)
  goto start

but I am not sure about the whole idea behind it though it resembles the derivative idea of Rob.

Also, how to determine the dt (time between measurements) given that I need the fastest response possible. Should I eliminate the "wait" statement and make dt just = millis() - last_millis() ?
Kp, Ki and Kd are tuning constants and that, I suspect, is more a matter of trial and errors.

How could I apply it to my problem (slow decay curve)?

Thanks