Avoid the ussage of the delay() function igram at all. This function will block the execution of the sketch in realtime.