I have an Arduino UNO hooked up to an ultrasonic rangefinder which reads into the variable distance. However, I need to, on one second intervals, read the current distance and then store the previous distance (from the last second). I also need to be able to use these variables (Dprev and Dcurr) other places in my code.
I am presuming I need to put it into some sort of while loop that iterates every second, but I don't know how to put it all together, or use time in a loop.