In design we have started sphero. The code is a lot like scratch and beetle blocks or even turtle art. You can choose to draw, which means moving the sphero along the lines you have drawn on your laptop (lines have to be connected), or you can use block based (like scratch) or Java.

Square

To make a square with the sphero, it is alot like beetle blocks in real life. First you need to put a loop around the code, which needs to say repeat 4 times because a square has four sides. Next you need to add in a roll block, as the sphero rolls. Then you add in heading, as in where the sphero is heading and do plus 90 or 360/4 as a square has four sides. We did speed 59 which is kind of in the middle, not too fast, not too slow. One second will get us a bit less than a metre each time. Delay for 1 second at the end means to stop the sphero after each turn so it wont go out of control.

Here is a video of our sphero making a square:

Nonogon

For a nonogon, we just need to change the square code and put in repeat 9 instead of 4. We also need to change the turn from 90 to 45. If you are unsure what your turn is, add in a divided by block and type in 360 divided by the number of sides on your shape. Here is the nonogon code and video.

Pentagon

For a pentagon, we need to change the repeat to five, hence the name pentagon (5 sides). I do not know the angle for a pentagon, so I added a divided by block. In this I put 360/5, so it will turn whatever that equals. Now we should get a pentagon.

Execute

After we had made some shapes, we decided to have a play around and see what we could do. We found out that we could make our sphero make sound. There are all sorts of different sounds it can do, and we had a bit of fun playing around on the robot mode. When we saw the sound that said enemy detected, we decided that we could make our robot an enemy and code it to hit the enemy. We made it so that after it said enemy detected, it turned red. We did this using a light block, which you can also use to change and fade the colour which looks really cool.

We also found out that on the sensors, there is a block that says on collision. This means that when we hit our enemy then we can make our sphero say something like enemy destroyed. We found a block that says execute, so we used it so that when we hit our enemy (the chair) then it will say execute.

Here is a video of it working.

Here is the code:

Toss Game

The next tutorial was the toss game. Here is the code, which I will explain later.

The top part of it says stabalization off. The sphero is coded to automatically right itself, so if you turn it upside down, then it will turn up the right way again. Stabalization off means that it wont do this anymore, and now you can throw it, like needed in the toss game. The next bit makes the sphero say, ‘Play the toss game’. The sound actually comes from the ipad, but it does it in sink with the code. We then join a loop to the bottom of the code. This means that whatever code we put inside the loop will always activate. Inside we put an If/else block. Next to the if block, we put an accelerometer block. This controls the height of the sphero. We do total, so it is the total of the height, and then at the end it is a larger then block, and then 3. This means 3 gs, which is about two feet in the air. So, if you toss the sphero in the air higher than 3 gs, then it will do something. We made it so that the light flashes green, so you know you have tossed it high enough. The else block will be for what happens if it does anything else then go higher than 3 gs. So it will be lower than 3 gs. If it is lower than 3 gs, then it will flash red, so you know you haven’t tossed it high enough. Now, after this, below the code that makes it flash green, we make it play a random animal sound. If you toss it higher than 3 gs it will flash green and play a random animal sound. The aim of the game is to guess the animal sound you get when someone tosses the sphero to you.

Lights and sensors

The next tutorial makes the sphero change colours when it spins. Here is the code

It starts off the same as the last program, by turning the stabilization off, then saying ‘Spin sphero like top to change LED colours’. The program does exactly that. You have to add the forever loop and inside add the If/else. Inside the if, add the gyroscope block and change the axis to yaw. If the yaw axis is larger than zero, then…the sphero will do something. We want the sphero to get brighter, so we need to add the main LED block and do the colour from/with/channel of block. This will change the colour. You need to add a main LED block from the events blocks next to the change colour from. Next to that you will write green, so change colour from main LED with green channel of, and then add a divided by block. You add a gyroscope and again choose yaw. For the spinning top, you need to normalize the gyroscope spin rate, which is 0-2000. Then you need to do the colour, which is only 0-255, so every spin can represented as a colour. All together, you do 7.84. In the else loop you do the same thing, with the main LED and the Change colour from, except instead of green, this time you do red, so it gets darker when you spin less so you know that you haven’t spun much. In this one you do absolute value of yaw gyroscope divided by 7.84. Here is it working.

The Hot Potato Game

Here is the code for the hot potato game that we are going to show you how to make.

A variable is a thing that changes, so can be marked under a category and the code will react according to whatever it is. This program uses lots of variables which you have to make. First, start the game the way we have started our other ones. Stabalization off, as we are going to be tossing it. Then make it say, Play the hot potato game and wait. Next ad a loop forever block, so the code goes for the whole game. Create a variable called Expire, set it to number, and set the number to 0. Do the same with another variable called toss. Now ad the set block, and set it to expire. Ad a random block and set it to int. Int means a full number and float means a number with a decimal. You choose int to keep your program simple. Ad a loop until block and do a comparators block inside it. Set the value to greater than and ad Toss in the left hand side and in the right hand side ad Expire. If Toss is greater than expire than do something. Do a main LED block and set the colour for red and below that do raw motor left for 0 and right for full speed for 0.1 seconds. This will go for the whole game. Then ad an if block and do total accelerometer greater than 3 gs. If the accelerometer experiences more than 3gs then do something. Make it play the abrupt sound and continue. Make it flash yellow by adding the strobe block and do it for 0.1 seconds one time. Then do a set block and set it to toss. Ad a operator block and change it to adition. Ad toss into the start of the statement. Ad one to the toss variable each time the if/then statement is true. This means that each time you toss sphero, the toss count will be tracked. Then below that ad a delay block for 1 second. Play the you lose statement and continue. Set the main LED to yellow and do raw motor left and right for 255 speed for 2 seconds. This will make the sphero go crazy and hard to hold. Do another delay for 1 seconds block and then speak your out so the person knows that they’re out and wait. Then reset the toss to 0 so you can keep playing.

Here is a video of it working.

Java

Now that we have finished all the block tutorials, we are moving on to the first Java tutorial. Java is when you code with words instead of blocks. This is what all the bits of code mean:

The first bit tells it where to start pointing. Then it tells it to await, which means to wait until the speaking starts. It will say (‘Hello square!’) then set the main LED to the colour to red, 255, which is full red. Then it awaits the sound, which is the sound from the game section, which is the coin sound. It plays the coin sound when it starts. Then the main LED sets to full green. The next part of the code represents the loop used to make the square. It uses the heading plus 90 degrees. Then the main LED changes back to red and it repeats. Here is it working.