Back to Activity
Tutorial
Fruit keyboard
{% trans 'Sorry, your browser does not support canvas -- please either update your browser or submit your requirements by phone or email.' %}

Accelerometer

Loading Blockly...

Step 1 /8

Introduction

The Fruit keyboard program will check whether leg 0 has been touched, and scroll the name of the fruit if it has.

Let’s start by setting up the emulator to show the status of CodeBug’s legs.

Click on the cog at the top right of CodeBug.

Tick the Show leg controls box.

Click Apply button.

Step 2 /8

Configure leg

We need to configure CodeBug’s leg 0 to be an input.

Click the cog on your start block.

In the window that appears, tick the checkbox next to leg 0 input/output.

Click the cog again to close the window.

Step 3 /8

Set to input

We want to set leg 0 to a digital input.

Select the drop down menu next to “leg 0 as” on your start block, and select digital input.

Step 4 /8

If condition

We want CodeBug to scroll a message if a the leg circuit is complete. To do this we first need an if block.

From the If menu drag in an if block to an empty area of your workspace.his in an empty area of your workspace.

From the Inputs/Outputs menu drag a leg grounded block and snap it to your if block.

Step 5 /8

Conditional code

We need CodeBug to scroll the name of the fruit when the fruit it touched. Any code inside the if block will only run if the condition is true (i.e. leg 0 is connected to ground).

In your if block, put a scroll sprite block and attach a get string sprite block.

Change its text to the name of your fruit.

Step 6 /8

While loop

Make your code repeat so CodeBug can continuously detect the input.

Step 7 /8

Run your code

Click the Play button to run your code. The message will scroll while 0 leg is clicked.

Step 8 /8

Download your code

Click the Download button to download your program. Make sure to follow the download to CodeBug tutorial to load your program onto your bug.