# data[].attributes.attachment_link.readable_text
{Introduction }

Turn your micro:bit into a Rock Paper Scissors game that you can play with your friends!

{Step 1}

First we need to make a variable to keep track of whether we have a Rock, Paper or Scissors in our hand. A variable is a container for storing values. Click on the ||variables:Variables|| category in the Toolbox. Click on the Make a Variable button. Give your new variable the name "hand" and click Ok.

{Step 2}

Click on the ||variables:Variables|| category in the Toolbox again. You'll notice that there are some new blocks that have appeared. Drag a ||variables:set hand|| block into the ||input:on shake|| block. We'll start our Rock Paper Scissors game when we shake 👋 our micro:bit.

let hand = 0; input.onGesture(Gesture.Shake, function() { hand = 0 })

{Step 3}

Click on the ||math:Math|| category in the Toolbox. Drag a ||math:pick random|| block and drop it into the ||variables:set hand|| block replacing the number 0. Now when we shake our micro:bit, the variable hand will contain a random number between 1 and 3.

let hand = 0; input.onGesture(Gesture.Shake, function() { hand = randint(1, 3) })

{Step 4}

Click on the ||logic:Logic|| category in the Toolbox. Drag the ||logic:if true then else|| block out to the workspace and drop it into the ||input:on shake|| block under the ||variables:set hand|| block.

let hand = 0; input.onGesture(Gesture.Shake, function() { hand = randint(1, 3) if (true) { } else { } })

{Step 5}

From the ||logic:Logic|| category, drag a ||logic:0 = 0|| comparison block and drop it into the ||logic:if true then else|| block replacing true.

let hand = 0; input.onGesture(Gesture.Shake, function() { hand = randint(1, 3) if (0 == 0) { } else { } })

{Step 6}

Click on the ||variables:Variables|| category in the Toolbox. Drag a ||variables:hand|| block out and drop it into the ||logic:0 = 0|| comparison block replacing the first 0. Click on the second 0 in the comparison block and change to 1.

let hand = 0; input.onGesture(Gesture.Shake, function() { hand = randint(1, 3) if (hand == 1) { } else { } })

{Step 7}

Click on the ||basic:Basic|| category in the Toolbox. Drag a ||basic:show icon|| block out and drop it under ||logic:if hand = 1 then||. In the ||basic:show icon|| block, click on the Heart icon and instead select the small square icon to represent a 💎 Rock.

let hand = 0; input.onGesture(Gesture.Shake, function() { hand = randint(1, 3) if (hand == 1) { basic.showIcon(IconNames.SmallSquare) } else { } })

{Step 8}

At the bottom of the ||logic:if then else|| block, click on the plus '+' sign. This will expand the code to include an ||logic:else if|| clause.

let hand = 0; input.onGesture(Gesture.Shake, function() { hand = randint(1, 3) if (hand == 1) { basic.showIcon(IconNames.SmallSquare) } else if (false) { } else { } })

{Step 9}

From the ||logic:Logic|| category, drag a ||logic:0 = 0|| comparison block and drop it into the open space next to the ||logic:else if|| clause.

let hand = 0; input.onGesture(Gesture.Shake, function() { hand = randint(1, 3) if (hand == 1) { basic.showIcon(IconNames.SmallSquare) } else if (0 == 0) { } else { } })

{Step 10}

From the ||variables:Variables|| category, drag a ||variables:hand|| block and drop it into the ||logic:0 = 0|| comparison block replacing the first 0. Click on the second 0 in the comparison block and change to 2.

let hand = 0; input.onGesture(Gesture.Shake, function() { hand = randint(1, 3) if (hand == 1) { basic.showIcon(IconNames.SmallSquare) } else if (hand == 2) { } else { } })

{Step 11}

From the ||basic:Basic|| category, drag a ||basic:show icon|| block out and drop it under ||logic:else if hand = 2 then||. In the ||basic:show icon|| block, click on the Heart icon and instead select the large square icon to represent 📃 Paper.

let hand = 0; input.onGesture(Gesture.Shake, function() { hand = randint(1, 3) if (hand == 1) { basic.showIcon(IconNames.SmallSquare) } else if (hand == 2) { basic.showIcon(IconNames.Square) } else { } })

{Step 12}

Now let's deal with the last condition - if our hand variable isn't holding a 1 (Rock) or a 2 (Paper), then it must be 3 (✀ Scissors)! From the ||basic:Basic|| category, drag another ||basic:show icon|| block out and drop it into the last opening under the ||logic:else||. In the ||basic:show icon|| block, click on the Heart icon and select the Scissors icon.

let hand = 0; input.onGesture(Gesture.Shake, function() { hand = randint(1, 3) if (hand == 1) { basic.showIcon(IconNames.SmallSquare) } else if (hand == 2) { basic.showIcon(IconNames.Square) } else { basic.showIcon(IconNames.Scissors) } })

{Step 13}

Let's test your code! Press the white SHAKE button on the micro:bit on-screen simulator, or move your cursor quickly back and forth over the simulator. Do you see the icons for rock, paper and scissors randomly appear? ⭐ Great job! ⭐

{Step 14}

If you have a micro:bit device, connect it to your computer and click the |Download| button. Follow the instructions to transfer your code onto the micro:bit. Once your code has been downloaded, attach your micro:bit to a battery pack and challenge another micro:bit or a human to a game of Rock, Paper, Scissors!

{Step 15}

Go further - Try adding 🎵 Music 🎵 blocks to your Rock Paper Scissors game for different sound effects. Note that some Music blocks may require a micro:bit v2 device to play.

let hand = 0 input.onGesture(Gesture.Shake, function () { hand = randint(1, 3) if (hand == 1) { basic.showIcon(IconNames.SmallSquare) music.play(music.builtinPlayableSoundEffect(soundExpression.giggle), music.PlaybackMode.UntilDone) } else if (hand == 2) { basic.showIcon(IconNames.Square) music.play(music.tonePlayable(262, music.beat(BeatFraction.Whole)), music.PlaybackMode.UntilDone) } else { basic.showIcon(IconNames.Scissors) music.play(music.createSoundExpression(WaveShape.Square, 1600, 1, 255, 0, 300, SoundExpressionEffect.None, InterpolationCurve.Curve), music.PlaybackMode.UntilDone) } })

input.onGesture(Gesture.Shake, function() {})

# data[].attributes.attachment_link.description
Turn your micro:bit into a Rock Paper Scissors game that you can play with your friends! First we need to make a variable to keep track of whether we have a Rock, Paper or Scissors in our hand. A variable is a container for storing values. Click on the ||variables:Variables|| category in the Toolbox.

# data[].attributes.attachment_link.readable_text
Count your steps with the micro:bit!

Turn your micro:bit into a step counter (also known as a pedometer). We'll use the motion sensor (also known as an accelerometer) to measure when we take a step with the micro:bit.

{Step 1}

First we need to create a variable to keep track of the number of steps 🦶. A variable is a container for storing values.
Click on the ||variables:Variables|| category in the Toolbox. Click on the Make a Variable button. Give your new variable the name "steps" and click Ok.

{Step 2}

Click on the ||variables:Variables|| category in the Toolbox. You'll notice that there are some new blocks that have appeared. Drag a ||variables:set steps|| block into the ||basic:on start|| block. This sets the value of our ||variables:steps|| variable to 0 when our program starts.

{Step 3}

Let's record a step every time our micro:bit shakes. Click on the ||input:Input|| category in the Toolbox. Drag an ||input:on shake|| block out to the workspace and place it anywhere.

input.onGesture(Gesture.Shake, function () {})

{Step 4}

Click on the ||variables:Variables|| category in the Toolbox. Drag a ||variables:change steps|| block into the ||input:on shake|| block. Now every time we shake our micro:bit (or take a step), we will add 1 to the value in our ||variables:steps|| variable.

let steps = 0 input.onGesture(Gesture.Shake, function () { steps += 1 })

{Step 5}

Let's show the number of steps taken. Click on the ||basic:Basic|| category in the Toolbox. Drag a ||basic:show number|| block into the ||input:on shake|| block, underneath the ||variables:change steps|| block.

let steps = 0 input.onGesture(Gesture.Shake, function () { steps += 1 basic.showNumber(0) })

{Step 6}

Click on the ||variables:Variables|| category in the Toolbox. Drag a ||variables:steps|| block into the ||basic:show number|| block, replacing the number 0.

let steps = 0 input.onGesture(Gesture.Shake, function () { steps += 1 basic.showNumber(steps) })

{Step 7}

Let's test your code! Press the white SHAKE button on the micro:bit on-screen simulator, or move your cursor quickly back and forth over the simulator. Do you see the number of steps increasing on the micro:bit? ⭐ Great job! ⭐

{Step 8}

If you have a micro:bit device, connect it to your computer and click the |Download| button. Follow the instructions to transfer your code onto the micro:bit. Once your code has been downloaded, attach your micro:bit to a battery pack and put in your sock. Walk around. Is the micro:bit counting your steps?

{Step 9}

Go further - you may notice the micro:bit can't count as fast you might run. That's because there is a delay while the micro:bit is displaying numbers. To correct for this, click on the Hint to see an alternate solution. Learn more about how the micro:bit acccelerometer works by watching this video.

let steps = 0 input.onGesture(Gesture.Shake, function () { steps += 1 led.stopAnimation() }) basic.forever(function() { basic.showNumber(steps) })

# data[].attributes.attachment_link.description
Turn your micro:bit into a step counter (also known as a pedometer). We'll use the motion sensor (also known as an accelerometer) to measure when we take a step with the micro:bit. First we need to create a variable to keep track of the number of steps 🦶.

# data[].attributes.attachment_link.description
Scratch is a free programming language and online community where you can create your own interactive stories, games, and animations.

# data[].attributes.attachment_link.readable_text
Materials

micro:bit, battery holder and 2 AAA batteries

Banana

Orange

4 Crocodile clips

Steps

|Step 1| - Connect the ground lead

Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin of the micro:bit.

|Step 2| - Connect the sound lead

Using the 2nd crocodile clip, connect the end of the crocodile clip onto pin 0 of the micro:bit.

|Step 3| - Connect the headphone to ground

Using the 1st crocodile clip, connect the second end of the crocodile clip onto based of the headphone jack.

Using the 2nd crocodile clip, connect the second end of the crocodile clip onto tip of the headphone jack.

|Step 5| - Connect a fruit lead

Using the 3rd crocodile clip, connect the end of the crocodile clip onto the 1st crocodile clip already clipped onto GND.

|Step 6| - Connect the orange to ground

Using the 3rd crocodile clip, connect the unattached end of the crocodile clip onto the orange.

|Step 7| - Connect a second fruit lead

Using the 4th crocodile clip, connect the end of the crocodile clip onto pin 1 on the micro:bit.

|Step 8| - Connect the banana

Using the 4th crocodile clip, connect the unattached end of the crocodile clip onto the banana.

|Step 9| - Complete banana keyboard

Your banana keyboard is ready!

|Step 10| - Test the keyboard

Connect your micro:bit to your computer using your USB cable and run this script:

input.onPinPressed(TouchPin.P1, () => { music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quarter)); });

Grab a the orange with one hand. With the fingers of your other hand, tap the banana to play sound. Your banana keyboard is ready!

# data[].attributes.attachment_link.description
micro:bit, battery holder and 2 AAA batteries Banana Orange 4 Crocodile clips Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin of the micro:bit. Using the 2nd crocodile clip, connect the end of the crocodile clip onto pin 0 of the micro:bit.

# data[].attributes.attachment_link.title
BBC micro:bit | Micro:bit Electro Football | Free Platform for Coding, Making and Inventing | Make | Tech Will Save Us

# data[].attributes.attachment_link.description
Welcome to the BBC micro:bit Make page. Follow these steps to create the Micro:bit Electro Football. Start this project now!