We are going to use CodeBug to sense if the wand touches the course. Let’s start by configuring the CodeBug emulator to help us out.
Click on the cog at the top right of CodeBug.
Tick the Show leg controls box.
Click Apply button.
The emulator will show the status of CodeBug’s legs with blue arrows. An arrow pointing towards the leg is an input, away from the leg is an output. When the background of a leg is red, the leg is at power, when the background is black, the leg is at ground.
To sense the wand, we need to configure CodeBug’s leg 1 to be an input.
Click the cog on your start block.
In the window that appears, tick the checkbox next to leg 1 input/output.
Click the cog again to close the window.
We want to set leg 1 to an input.
Select the drop down menu next to “leg 1 as” on your start block, and select digital input.
We want CodeBug to run different code depending on if a the leg circuit is complete. To do this we need an If block.
We need different code depending on whether the circuit is complete or not. Any code inside the if block will only run if the condition of the if block is true (e.g. leg 1 is connected to ground).
Inside the gap of your if block, put a scroll sprite block with a get string sprite block.
Change its text to Game over.
Make your code repeat so CodeBug can continuously detect the input. For this we will need a repeat while true loop.
Click the Play button to run your code. The message will scroll while 1 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.