You need to use timers and maybe interrupts (though this doesn't sound timing-critical so maybe ditch the interrupts). It's covered in the example sketches as suggested.
You need to use timers and maybe interrupts (though this doesn't sound timing-critical so maybe ditch the interrupts). It's covered in the example sketches as suggested.