Micro:bit

Introduction to Micro:bit

We were introduced to the micro:bit this week. It is a small computer that has built in inputs that allows it to function. We were introduced with two ways to program it. One way was to use blocks, making it a very easy way for children to learn how to use it and program it. The other way was JavaScript, which takes more time but also can allow a wider variety of commands. We created two programs, one Hello World program ( input.onButtonPressed(Button.A, () => { basic,showString("Hello World!")})) and one emotion program. You can preview the code of my emotion project here.

input.onGesture(Gesture.Shake, () => {
for (let i = 0; i < 4; i++) {
basic.showLeds(`
. # . # .
. # . # .
. . . . .
. . # . .
. # . # .
`)
basic.showLeds(`
. # . # .
. # . # .
. . . . .
. # . # .
. . # . .
`)
}
})
input.onButtonPressed(Button.A, () => {
basic.showLeds(`
. # . # .
. # . # .
. . . . .
. # . # .
. . # . .
`)
})
input.onButtonPressed(Button.B, () => {
basic.showLeds(`
. # . # .
. # . # .
. . . . .
. . # . .
. # . # .
`)
})
input.onButtonPressed(Button.AB, () => {
basic.clearScreen()
})

Light Sensor and Sounds

In this program, we utilized the light sensors and the pins. The program would play a sound when exposed to a certain amount of light and a melody when the a button was pressed. We connected speakers to the micro:bit with alligator clips. Overall, it taught me how to use some of the features built into the micro:bit. You can see my code below.

input.onButtonPressed(Button.A, () => {
music.beginMelody(music.builtInMelody(Melodies.Entertainer), MelodyOptions.Once)
})
basic.forever(() => {
led.plotBarGraph(
input.lightLevel(),
255
)
if (input.lightLevel() > 180) {
music.playTone(208, music.beat(BeatFraction.Double))
music.rest(music.beat(BeatFraction.Whole))
music.playTone(277, music.beat(BeatFraction.Whole))
music.rest(music.beat(BeatFraction.Whole))
music.playTone(330, music.beat(BeatFraction.Whole))
music.rest(music.beat(BeatFraction.Whole))
}
})

Final Project

Our final project was to make something with the micro:bit. If you could imagine it, you could make it. We had a list of ideas that we could choose, but also had the choice to choose our own idea. For my final project, I created a two player pong game. I wanted to do something that wasn't described. It was surprisingly hard the way I made it in JavaScript. The code itself is simple, but without a console, it was hard for me to find bugs. This time, I put notes inside the code so you can know what is happening. (This does not take away from functionality. It will still work with the notes.) I had to restart 2 times due to stupid keybind mistakes, lengthening the process. If I had more time on my hands, I'd clean the code up a bit, make it simpler. You can see the code as well as a video of it in action below.