Thanks but I don't quite understand how that works, if my device hangs on the reads for the sensors, is there any way I can have it skip over that part of the code?
Yes there is, what you're looking for is named an interrupt
, it lets you do pseudo-multitasking, which you're after.
In the code above I use a timer (something that counts up), I enable the overflow interrupt. The timer 2 is an 8-bit timer which means the overflow will happen at 255. This makes the program call the code which is inside the TIMER2_OVF_vect no matter what it was doing before
every 8MHz/256 = 31.25kHz. You can further slow down by setting a prescaler, what that does is divide the counting speed of the timer. How to set it and what exactly are all described in the datasheet of your MCU.TL;DR: search for "avr interrupt" on Google