I want to store a sample every 5ms. I'm using extra RAM to buffer and the buffer is going to be overwritten by the new samples when it reached to end of the RAM capacity. However, I also want to do other stuff besides taking samples. How can I be sure that the time between two sensor values is approximately 5ms? I've got an RTC connected to my Arduino unit.
void loop() {
if(micros()-time > 5000) {
time = micros();
//get samples
//do other stuff
}
// do some stuff here but be careful no to take to long (< 5mS)
}
every time through the loop it checks if 5mS elapsed if so zero time and get data and store