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

Programming and Making

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.

Elementary School ~ Beginner 15 min

What You Need

  • SPACEBLOCK
  • USB cable
  • Battery box
  • 8×8 RGB LED Matrix Panel (LED panel)*
  • A computer for programming
* The 8×8 RGB LED Matrix Panel (LED panel) is not included in the SPACEBLOCK Standard Package, but you can buy it separately on the SPACEBLOCK website.
Top, from left: battery box, USB cable. Bottom, from left: LED panel, SPACEBLOCK

Getting Ready: Connect the LED Panel to SPACEBLOCK

Connect SPACEBLOCK to your computer with the USB cable, and connect the battery box too. Plug the 3 pins on the back of the LED panel into the sideways pin socket on SPACEBLOCK. You only use the battery box in standalone mode, so keep its power OFF when you aren't using it.
Check what connects where on 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.

If the top left of the programming screen (next to the SPACEBLOCK logo) doesn't say "Device ON," click it to connect

Make a Program That Controls the LED Panel

First, let's make a program that lights up the LED panel. On the programming screen, choose the [RGB LED (A10): light up] block in the [LED] category.
Click a category to see the blocks you can use, then drag one out

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.

A program that shows an apple 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.

If you choose a number other than A10, your instructions won't reach the LED panel

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

Next, add one more [RGB LED (A10): light up] block and show a banana. Build the program as in the next picture and run it. The apple doesn't show up, only the banana does! If you watch carefully, though, something seems to flash red for a moment before the banana.
We programmed an apple and a banana, but only the banana shows up

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.

With a pause block, you can see the apple

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.

A program that shows the apple and the banana for 2 seconds each, then turns off

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!

QR code for project