Did you perhaps mean prev_t = now?
I did.
The only thing I don't quite understand is how the if statement is working. Wouldn't "now - prev_t" always simply be 1?
After one millisecond, yes. After less than that, like on the next pass through loop, the difference will be 0. After a while, the difference will go to 2, then 3, then 4, etc., until it exceeds the defined interval (tMil). Then, prev_t will be updated.