The micro:bit

Blocks, micro:bit, Scratch2.0

The micro:bit is a tiny computer that you can program with blocks and also with other programming languages. It has two buttons, 25 LEDS, and some more sensors built in, you can add more sensors (to pick up and measure events and data) and activators (lamps, other items to do something). If you are fancy to see more, have a look here on this website, there are more projects! Today you can create a small Rock, Paper, Scissor game, follow the link below.

190918 GOLForMicroBit.jpg

Rock Paper Scissors Activity

How to use the micro:bit?

First, connect your micro:bit with the USB cable to the computer. Then you launch the editor  and write your code. At the end you need to compile (translate) the code into something the processor on the micro:bit can understand and download it. When the download is finished (a red LED on the micro:bit will stop blinking) the program will start automatically. You’re done, congratulations!

Scratch

Animation, Blockly, Blocks, Game

Scratch is a block based programming language. You do not need to type code, but you just assemble projects with blocks of different functionality and configure those with simple entry of numbers and text. Scratch runs on a web browser and you can also interface it with some hardware. But where to start with Scratch?

The Code Club is a UK charity that promotes computer science for young people as yourself.  They offer very comprehensive and detailed project tutorials, from small animations to a more complex  RPG(*) game.

Here is the link to the site:

Code Club Project Create your own world

(*) A role-playing game (sometimes spelled roleplaying game;[1][2] abbreviated RPG) is a game in which players assume the roles of characters in a fictional setting. Players take responsibility for acting out these roles within a narrative, either through literal acting, or through a process of structured decision-making regarding character development.[3] Actions taken within many games succeed or fail according to a formal system of rules and guidelines.[4] [Source: Wikipedia]

Micro:bit – Accelerometer, the Game Blocks and a Catch Game Part I

Blocks, Game, micro:bit, Uncategorized

For this game we need to use the accelerometer to sense the orientation of the micro:bit. This sensor is comprehensively described in the documentation. You find it under “Reference”.

mb_Accelero

Let’s have a look at one sensor, we choose the accelerometer. It measures acceleration, caused by gravity and sudden movements. Here is a sketch explaing about the three coordinates it uses to put the acceleration into numbers. You can measure the acceleration in on direction (x, y, z) at a time. The values change between -1023 and 1023.

mb_coordSys

Here is the link accelerometer so that you can have a look.

The documentation is interactive, so you can also upload a sketch to the IDE and run it there. Furthermore, you find examples that you can also easily transfer to the editor, no need to rebuild the projects.

Get to know sensors and how to program them.

Get the examples running on the simulator and your micro:bit. As a next step find the documentation for the magnetic sensor and implement a compass.

Game module

In the micro:bit editor under Advanced you find the category “Game”. It contains blocks to make small games.

The small display of the micro:bit contains 5 x 5 LEDs. In the game module you can address each LED with its coordinates (x, y). You may know coordinate systems from school, they have their origin (0,0) always at the lower left corner. In computer science we normally put the origin at the upper left corner.

mb_coordSysLED

Create your first game

Following you find the beginnings of a small game. At the beginning of the game a LED will light up at a random location. Then the player needs to move the other LED to that location using the buttons A and B. When he reaches the final position, the display shows “Win!”. The button A is already coded, try to understand what is happening when you press the button. Then finish the game by coding the functionality for button B.

181002_Catch1


let dir_x = 0
let sprite2: game.LedSprite = null
let sprite1: game.LedSprite = null

sprite1 = game.createSprite(2, 2)
sprite2 = game.createSprite(Math.random(5), Math.random(5))
dir_x = 1

basic.forever(() => {
if (sprite1.isTouching(sprite2)) {
basic.showString("Win!")
}
})

input.onButtonPressed(Button.A, () => {
if (sprite1.isTouchingEdge()) {
dir_x = dir_x * -1
}
sprite1.change(LedSpriteProperty.X, dir_x)
})

input.onButtonPressed(Button.B, () => {
})

Above is the code in Javascript, open the micro:bit Javascript editor, select “{}Javascript” and then copy and paste the code into the editor. Next, select “Blocks” and the code will be converted into the Block language. Here you can now

  • try out the program,
  • figure out what is happening when you press  Button A and
  • then add the missing functionality for button B.

Micro:bit – First experiments With a Game I

Blocks, micro:bit

In the future you will find here links to external and internal materials that help you to get faster up to the interesting activities.

For today I only post here one link, that is for the additional micro:bit project you may be able to do today.

You can create a simple Truth or Dare game with the micro:bit. When pressing the button A, the micro:bit will calculate a random number between 0 and 4. If the micro:bit chooses a 0, you will see “Truth” displayed on the screen, otherwise “Dare”.

180919 TruthOrDareScreenS

Truth or Dare with micro:bit

This small project has already all ingredients of a real programm, it uses a variable, a loop, a conditional if statement and works at least in parts sequentially. We will discuss those elements further next week.

Enjoy