loop() function, you create "reflexes" for your sketch, saying "Whenever this type of packet arrives, call that function to handle it." Reflex packet handling is the SFB's 'native tongue' -- it is what SFB's use, by default, to talk to each other, and it underlies the 'code flow protocol' that allows SFB's to download sketches from host computers and each other.Using the packet system in your sketch can feel quite strange at first, because the sketch never actually reads any input. What is really happening is that the core software is collecting input bytes that arrive from the outside world, and storing them in memory. The sketch isn't bothered unless a complete line of text -- a complete 'packet' -- is available, and the sketch has expressed an interest in packets of that type.
Consider these examples:
Alarms system to make that easy. You write an 'alarm handler' function, and create and set an alarm, and when the alarm goes off your alarm handler gets called.Alarms can be used for one-shot or repeating events, they can be canceled, or reset for a different time, before or after they have gone off, and dozens of them are available for sketch use. Alarms provide resolution down to the millisecond, but they don't guarantee perfect accuracy: An alarm handler may be called right on the millisecond for which it was scheduled, but it may run one or more milliseconds later, depending on how busy the system is.
Alarms system provides, you can use a hardware timer. There are three hardware timers specifically reserved for sketch use, named Timer1, Timer2, and Timer3. In addition, there is a fourth timer (named Timer4, naturally) also available, but that hardware is shared with the hardware PWM (Pulse Width Modulation, see PWMSketches) system, so a single sketch cannot use both hardware PWM and Timer4.
Hardware timers are a more advanced topic, primarily because (unlike with Alarms) the 'handler' functions you write are executed with interrupts disabled, meaning that while your handler is running, nothing else is happening -- no input is being read, no output is being shipped, the millis() clock isn't ticking, and so on. So you need to keep your timer handler functions relatively short and simple as much as possible.
But, that said, don't be afraid! Sometimes a hardware timer is just the right tool for the job!