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.
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.
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.
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.
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.
Make your code repeat so CodeBug can continuously detect the input.
Click the Play button to run your code. The message will scroll while 0 leg is clicked.
Click the Download button to download your program. Make sure to follow the download to CodeBug tutorial to load your program onto your bug.