Episode 1 A New “Hello World”

Almost every computer language or platform uses a “Hello World” program as the first example. For desktop or server environments, it typically prints the string “Hello World”. For embedded platforms such as a micro:bit, it simply blinks an LED.

Some may think, “How hard could it be to blink an LED?” Indeed most examples I have seen involve just a forever-loop with a pin toggling function and a delay/sleep call in the loop. In the makecode environment, it looks like this:

Figure 1

It works! Later on in order to add more business logic or behaviors, we would naturally attempt to stuff other function calls, conditional statements (if-else) and probably more delays in the loop. It is a simple and obvious way to make a system run continuously and do something repeatedly. So what are the problems with this that we need a new design?

The main problem lies in the heart of its sequential processing model. The system performs its tasks step by step, one at a time. It is not a big problem when a step, like toggling an LED, is super fast. However it becomes a problem when a step is to wait for something to happen, like waiting for a timeout to occur as in pause(). While it is waiting, the system is not doing anything else, and is therefore unresponsive to any input from the world. It is not very nice to say “Hello” to the world but ignore what’s happening in it, is it?

If you are building a batch processing system that cranks through a database at midnight, or training your machine learning algorithm over a big collection of data, you don’t need to care about responsiveness. It is unlikely, though, that you are going to do that with your micro:bit. More likely you are building something fun to interact with the real world.

This kind of systems are commonly known as real-time embedded systems, and you will learn a lot about them here at Gallium Studio. First we need to find an alternative to the sequential processing model, which will be introduced in the next post.