void loop() 1 void loop() 2

Time everything using millis() instead of using delay() which blocks the sketch. Blocking means that nothing else can happen. Timing means starting something, noting the time and then checking whether it is time to start something else or stop something. The blink without delay example shows this approach. Once you get the hang of it, it's easy.