Introducing CodeBug! |
We start the project by visiting the CodeBug website http://www.codebug.co.uk and creating an
account. It only takes a few minutes. While logged in, clock on Create to start a new project. Don't forget to save your work!
The interface for CodeBug contains an area to the right of the screen with is the primary programming interface. There are a series of menus that are used to store the blocks with can be dragged from the menus into the coding area. Good blocks are made to connect together, and that is what we intend to do!
Now that you have familiarized yourself with the interface, let's get started on an intermediate project Thomas Macpherson-Pope pulled together from CodeBug.org.uk
What you need:
Metal Coat Hanger
Plastincine/Blu-Tac
Crocodile Clips
Computer
The Project
Would you like to play a game?Let's make one with CodeBug!The Steady hand game involves trying to get a metal wand from one side of a wavy wire to the other, without the two touching. The game works because it is made from an incomplete electrical circuit. When the metal wand touches the metal wire course, the circuit is completed and this triggers an alarm. CodeBug can sense when the circuit is completed using its legs, and can then tell the player that they have lost the game.
The Program should simply detect if Leg 1 (attached to the wavy course) has been connected to the Ground Leg (attached to the metal wand). If this happens, you then need to scroll a message telling the player that the game is over.
To set the Legs of the CodeBug we will need to first configure the Emulator. To do this we will need to open the emulator configuration via the settings cog on the emulator. Tick the Show Leg Controls box. Click on the Configure Emulator button to complete the settings change. The emulator will now show the status of the CodeBug's legs with blue arrows. The arrow pointing into the legs denotes that it's set as an Input; away from the legs is an Output. When the background of the leg is red, the leg is at Power, when the leg is black, it is Ground.
With the program working we can now send that over to the CodeBug.
With the code working, click on Download; it's just under the emulator controls. When the code downloads, plug a USB to micro USB cable into your computer. While holding Button A of your CodeBug also insert the micro USB into the CodeBug. The top left LED in the matrix on the CodeBug will flash. Your computer should also recognize the CodeBug as a USB drive on your computer. Copy the downloaded code from the CodeBug website to the USB drive and run the program by pressing Button B. If your CodeBug is on battery power, you can now disconnect the USB cable.
Now that the Emulator has been configured, we can begin programming the legs. To do this we will need to click on the Cog of the Start block. From the popup we can drag the Leg Input/Output block into the Start block on the right. Because we want the Leg to sense a button, we will need to tell CodeBug to use Leg 1 as an Input.
We want CodeBug to run different code depending on if a leg's circuit is complete. To do this we will need an If block. From the Inputs/Outputs menu drag a Leg Grounded block and snap it to your If block. Click the block's drop down menu to change the Leg to 1.
We will need a difference code to run if the circuit is complete. Any code inside the If block we just did will only run if the condition of the If block is True (Leg 1 is connected to Ground). Lets first put a Scroll Sprite block in the If block. Next we can attach a Get String Sprite block into the Scroll Sprite puzzle piece. Next we will change the default "Hello World" to "Game Over". We'll also need to make the code repeat so the CodeBug can continuously detect the input. To do this let's grab a Repeat While True from the Loops menu. We will snap it into the Start block and the If block into the While Loop.
Now it's time to see if it works via the Emulator...
The course consists of a metal wavy path and a metal wand.
- Break the loop of your coat hanger and then bend it into a fun shape.
- Attach a croc-clip to one end of your coat hanger and the other clip to Leg 1 on CodeBug.
- Make a wand with another piece of wire with a loop at one end. Feed the wire through the wand loop.
- Use plasticine to secure the two ends of the wire course, creating two bases so the course stands upright.
- Attach a croc-clip from the end of your wand to the Ground Leg on CodeBug.
Make sure your metal wire and wand have no sharp edges!
See more CodeBug projects and learn how you can get one of your own by visiting: 10 CodeBug Projects in 10
Top Comments