In the usual flow of SFB affairs, packets are input from any of the four faces and are reacted to, and output packets are sent out to any of the four faces, from packet handlers, Alarm handlers, or the
loop() method. But sometimes more fine-grained control over packet handling is needed, and the core software provides more advanced mechanisms for that purpose.
For debugging, display, or just fun, we often want to blink the onboard LEDs in response to events. The 'good old-fashioned way' to blink an LED is (1) Turn it on, then (2) Delay for a while, then (3) turn it off, but if we do that -- step (2) specifically -- inside a packet (or alarm) handler, we can run into trouble. Since only
one handler runs at a time,
all handler functions (packet or alarm) need to be relatively quick, to give the other handlers a chance. But calling
delay() is the
opposite of being quick.
The QLED object (an instance of SFBQLED) provides a way to schedule LED 'on' and 'off' 'events' without calling delay().
In the basic tutorials,
Using the EEPROM illustrated the primary functions used for accessing the EEPROM. Here we touch on one additional function --
eepromWait() -- and look at an advanced mechanism for initializing EEPROM data.
As an advanced technique, if you need more accurate timing than the
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
Using the hardware PWM module) 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!
--TO COME--
--TO COME--