BBC micro:bit
Matrix Helper

Introduction

This project is about making a Visual Basic program to help you quickly create the code for images in MicroPython.

To write the program, I used Visual Basic 2015 in the Visual Studio 2015 Community Edition. This is free to download and use. Other versions are likely to work the same for this program.

Visual Basic - Form Design

First you need to create a new project. Choose to make a Visual Basic Windows Application and give the project a suitable name before pressing the create button.

Design your form using the tools in the toolbox. When an object is selected, the Properties Window will allow you to change its properties. The form will need to look like this,

VB Program

There are two buttons and a text box. The buttons are called btnClear and btnMake - set their names and text in the properties window.

The TextBox is called txtOuput and has its multiline property set to true and scrollbars to both.

The space at the top left is for the pixel grid. You need to leave around 200 pixels square.

Visual Basic - Code

The full code for this project is shown below,

Dim picPixel(4, 4) As PictureBox

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
   For y As Integer = 0 To 4
      For x As Integer = 0 To 4
         picPixel(x, y) = New PictureBox()
         With picPixel(x, y)
            .Size = New Size(30, 30)
            .BorderStyle = BorderStyle.FixedSingle
            .BackColor = Color.White
            .Location = New Point(10 + (x * 35), 10 + (y * 35))
         End With
         AddHandler picPixel(x, y).Click, New EventHandler(AddressOf PictureBox_Click)
         Me.Controls.Add(picPixel(x, y))
      Next
   Next
End Sub

Sub PictureBox_Click(sender As Object, e As MouseEventArgs)
   Dim p As PictureBox = sender
   If p.BackColor = Color.White Then
      p.BackColor = Color.Red
   Else
      p.BackColor = Color.White
   End If
End Sub

Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
   For y As Integer = 0 To 4
      For x As Integer = 0 To 4
         picPixel(x, y).BackColor = Color.White
      Next
   Next
End Sub

Private Sub btnMake_Click(sender As Object, e As EventArgs) Handles btnMake.Click
   Dim s As String = ""
   For y As Integer = 0 To 4
      For x As Integer = 0 To 4
         If picPixel(x, y).BackColor = Color.White Then
            s = s & "0"
         Else
            s = s & "9"
         End If
      Next
   s = s & ":"
   Next
   s = "Image('" & s & "')"
   txtOutput.AppendText(s & vbNewLine)
End Sub

Using The Program

Launch the program and make some images. Press the Make button each time you finish an image.

VB Program

Copy and paste the text using keyboard shortcuts (CTRL + C) and make a Python program like this,

from microbit import *

imgs = [
    Image('90000:00000:00000:00000:00000:'),
    Image('90000:09000:00000:00000:00000:'),
    Image('90000:09000:00900:00000:00000:'),
    Image('90000:09000:00900:00090:00000:'),
    Image('90000:09000:00900:00090:00009:')
]
display.show(imgs, delay=500,loop=True)

This is simple diagonal line drawn from top left to bottom right.

Challenges

  1. The easiest thing to do is to make some more animations. Keep making your images until you have something cool to display on the matrix.
  2. A greater challenge is to add features to the Visual Basic program, like being able to choose the brightness of the pixel.