[No.4] The Basics of Programming: Get the Order Right! Show Fruit on an LED Display

Let's make your very first program with SPACEBLOCK, the tiny computer for making things. This time, you'll connect the 8×8 RGB LED Matrix Panel (we'll call it the "LED panel") and try making a device that shows pictures.
What You Need
- SPACEBLOCK
- USB cable
- Battery box
- 8×8 RGB LED Matrix Panel (LED panel)*
- A computer for programming

Getting Ready: Connect the LED Panel to SPACEBLOCK

Log in to the SPACEBLOCK website with your account, create a new project with [Add new project], and open the programming screen. Connect your device from the top left of the screen (next to the SPACEBLOCK logo), and build your program with "Device ON" showing.

Make a Program That Controls the LED Panel

Attach the [RGB LED (A10): light up] block to [Start Program], then draw the picture or pattern you want to show on the LED panel.

The "A10" in the [RGB LED (A10): light up] block is the number of the sideways pin socket the LED panel is plugged into. Like this, whenever you connect another part to SPACEBLOCK, you choose the number of the socket you used when you program it.

Run the program, and a bright apple appears on the LEDs.


The program has the apple in it, so why doesn't the apple show up? Let's fix the program so the apple appears first and then the banana.
Programs Run Super Fast! Add a "Pause"
If you check this program, the block that shows the banana is attached right below the block that shows the apple. A program runs from top to bottom at incredible speed. Here, the instruction to show the banana ran the instant after the instruction to show the apple, so it looked like only the banana was showing. The red flash you saw was the apple, visible for just a split second.
To fix it, put a [Pause for (1000) milliseconds] block from the [Basic] category right below the apple part of the program. Now when you run the program, the apple shows for 1 second, and then the banana appears.

Thanks to the [Pause for (1000) milliseconds] block, the apple stays visible for a while before the program moves on to the instruction that shows the banana. By the way, a "millisecond" is a unit often used in programming: 1 second is 1000 milliseconds.
Give the Computer Exact Instructions!
If you asked a friend, "Show me an apple and then a banana," they would show them one after the other at a sensible speed. But a computer only does what is written in the program, so it won't decide what a "sensible speed" is. You, the programmer, need to give the computer exact, detailed instructions in the right order, in a language it understands.
Remember: when you want the program to wait before moving on to the next block, like this time, use [Pause for (1000) milliseconds]. It's a trick you'll use all the time in programs that control lights and movement.
Now let's change the program a little more: show the apple for 2 seconds, then the banana for 2 seconds, and then turn off the LED panel. To turn off the LEDs, use the [Turn off all LEDs on RGB LED (A10)] block.

Transfer this program to SPACEBLOCK and run it in standalone mode.
Disconnect SPACEBLOCK from the computer and turn the battery box power ON. The apple and the banana each show for 2 seconds and then the LEDs turn off. To run the program again, turn the power OFF and then ON again.
A program that you build under the [Start Program] block starts running when you turn the power ON, just like this.
Next, we'll change the program so the LEDs don't light up right away when you turn on the power, but light up when you press a button. See you next time!