Sphero Macro Lab – Session 1

Sphero MacroLab is an excellent way of learning and experimenting with programming coding.

It works with macros, but… what is a macro, really?

The definition from wikipedia is “A macro (short for “macroinstruction”, from Greek μακρο- ‘long’) in computer science is a rule or pattern that specifies how a certain input sequence (often a sequence of characters) should be mapped to a replacement output sequence (also often a sequence of characters) according to a defined procedure.”

Wow it seems complex… but don´t worry, it isn’t. In my own words a macro is an easy and visual instruction that we can use directly in order to get one action rather than typing all the coding. For instance, imagine that we want to get the colour of the sphero orange.

  1. With a macro we could type the icon with the colours and change the percentages without typing.


2.  Just to open the led blue you would have to type something like this:

  private void blink(final boolean lit){
        if(mSphero != null){
            //If not lit, send command to show blue light, or else, send command to show no light
                mSphero.setColor(0, 0, 0);                               // 1
                mSphero.setColor(0, 0, 255);                             // 2

            //Send delayed message on a handler to run blink again
            final Handler handler = new Handler();                       // 3
            handler.postDelayed(new Runnable() {
                public void run() {
            }, 1000);

Much trickier eh?¿.

Macrolab reads the code from the top to the bottom.


In this example first the ball will calibrate, later will change the colour to purple, after that will roll for a certain time and will change the colour again to orange.

The follow videos are very explicative about the different commands, with some good examples. Enjoy them!


Leave a Reply