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:
CodeBug’s legs have magical properties. They can sense when something conductive is touching them, such as wire, people or even fruit! By connecting different pieces of fruit to CodeBug’s legs, you can get it to say which piece of fruit has been touched.
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 to the legs is the Input, away from the legs is the Output. When the background of the leg is red, the leg is at Power, when the leg is at black, it is Ground.
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.
From the If menu, drag in an If block to an empty area of your workspace. From the Inputs/Outputs menu drag a Leg Grounded block and snap it to your If block.Make sure to select from the drop down which leg you will be programming. From the Sprite menu drag in a Scroll Sprite block and place it inside your If block. Now also from the Sprite menu, drag in a Get String Sprite block and snap it onto your Scroll Sprite block. Change the default "Hello World" to the name of the fruit or vegetiable you will be using in conjunction with the leg ( I used "Apple". Now from the Loops menu, drag a Repeat While True block and snap it into the Start block. Finally drag the If block into this While loop.
Let's add more fruit the the program. From the If menu drag an If block to an empty space on your workplace. Click on the cog icon on your If block and, in the window that appears, drag an Else If into the If on the right.
Repeat the previous steps for adding in the Get String Sprite and Scrolling Sprite for the other Legs. Select from the drop down of the Leg Grounded block which Leg will correspond with what fruit.
From there we can run the Emulator with the code...
With the code working, click on Download, it's just under the simulator controls. When the code downloads, plug in a USB to micro USB into your computer. While holding Button A of your CodeBug also insert the micro USB to 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 code downloaded from the CodeBug website to the USB drive and run the program by pressing Button B.
Now let's wire up the fruit!
- Connect a croc-clip to the leg labeled GND.
- Connect another croc-clip from leg 0 to a piece of fruit.
Note: If your CodeBug has gone to sleep, wake it up by pressing either button A or B.
- Test your program by holding the croc-clip connected to ground (make sure you touch the metal part), while pressing the fruit repeatedly. You will see the text scroll as you touch the fruit.
Now you have made a simple fruit input, you can repeat the process by attaching more pieces of fruit with more croc-clips to CodeBug’s other numbered legs.
And there you have it a Fruit Keyboard for your CodeBug!
See more CodeBug projects and learn how you can get one of your own by visiting: 10 CodeBug Projects in 10 Days