Teaching Kids Programming – Introduction to Microbit Programming in Python


Teaching Kids Programming: Videos on Data Structures and Algorithms

The Microbit is a little device invented by BBC. This chip has 25 pixels (screen – output), 2 buttons (A and B) and a few pins that can be connected to external hardware. The Microbit supports Python and Javascript.

We can develop and test our code at the following Simulator:
https://makecode.microbit.org/#editor

The following Microbit code shows how to control buttons when A, B or A+B is pressed.

1
2
3
4
5
6
7
8
9
10
11
def on_button_pressed_a():
    basic.show_string("A")
input.on_button_pressed(Button.A, on_button_pressed_a)
 
def on_button_pressed_b():
    basic.show_string("B")
input.on_button_pressed(Button.B, on_button_pressed_b)
 
def on_button_pressed_ab():
    basic.show_string("AB")
input.on_button_pressed(Button.AB, on_button_pressed_ab)
def on_button_pressed_a():
    basic.show_string("A")
input.on_button_pressed(Button.A, on_button_pressed_a)

def on_button_pressed_b():
    basic.show_string("B")
input.on_button_pressed(Button.B, on_button_pressed_b)

def on_button_pressed_ab():
    basic.show_string("AB")
input.on_button_pressed(Button.AB, on_button_pressed_ab)

The following shows an animation of a running dot/pixel from left to right, top to bottom. led.plot(x, y) and led.unplot(x, y) sets and clears a pixel respectively.

microbit-simulator Teaching Kids Programming - Introduction to Microbit Programming in Python microbit Microsoft teaching kids programming youtube video

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
x = 0
y = 0
 
def onEvery_interval():
    global x, y
    led.unplot(x, y)
    x += 1
    if x == 5:
        x = 0
        y += 1
        if y == 5:
            y = 0
    led.plot(x, y)
 
loops.every_interval(200, onEvery_interval)
x = 0
y = 0

def onEvery_interval():
    global x, y
    led.unplot(x, y)
    x += 1
    if x == 5:
        x = 0
        y += 1
        if y == 5:
            y = 0
    led.plot(x, y)

loops.every_interval(200, onEvery_interval)

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
352 words
Last Post: How to Comply with GDPR in Adsense?
Next Post: Teaching Kids Programming - Design and Develop an Apple Catching Game on Microbit using Python

The Permanent URL is: Teaching Kids Programming – Introduction to Microbit Programming in Python

Leave a Reply