Pages

Friday 31 May 2019

Coding in DTE

What had we been learning?

For the past few weeks, in DTE we had been playing around with  Sphero Edu. An app that ables you to code anything you want to a robot. We were first introduced to it by codding the robot to go through a maze, controlling it to turn corners on a certain angle, stopping it on time and controlling the speed to get a hang of the app and see where things are. We then went through tutorial videos provided by the Sphero Edu website that taught us how to create games from the app, like the Toss  Hot Potato and Spinning top game teaching us about variables, sound and lights that further enhanced our knowledge on coding. After getting to know the app, we were then assigned to create our own, taking inspirations from the Sphero Edu website community and the games we learnt beforehand. I decided to code a memory toss game, inspired by the toss and spinning top game.



My plan for my game:

The memory toss game should be like the toss game from the website, however, instead of playing random animal sound it should play random times the lights would blink.

Sphero would detect how many times a player tosses the ball.

Aim: To test your memory by counting how many times the sphero blinked and toss it the same time it blinked.


Memory Toss Game

How to create the game?

Drag the loop forever block under the “on start program” this way you can continue playing without starting the program all over again.

Then go to the light and grab the main LED and put it inside the loop forever-this way you wont to keep clicking start to continue the game, since it would run until you tell it to stop.

Change to colour to black to take the lights away from the Sphero ball.

Then create variables and name them, after, before, answer, loops and puzzle. Makes sure to select number and keep it 0-Variables are blocks that you can set a value to later on.

Now go back to the variables tab and select the set __ to 0 blocks and place it underneath the main led block.

Now create a row of it using four of those.

Then change the middle bit to after, before, loops, puzzle in order.

After, put random integer from 0 to 0 from the operator to where the o zero is in “set puzzle to 0”

Change the integer from 1 to 9  this way Sphero would give a random number to blink from 1 to 9.

Delay it for 3 seconds.

Now set the back led to whatever intensity you want, I’m gonna set mine to 50

Get the “strobe (colour) for block” from the light section change the colour to white.

Set the seconds to 0.5.

Now get your variable puzzle and replace the 0 with it.

Go back to “main LED” and set the colour to black again with the black-led to 0.

This time delay it for 2 seconds.

Grab the “loop until block” and “place the true && true block” and put it inside.

In the comparators section, you can find a block that goes like this: 0 === 0, place it inside the true spaces on the left and right.

Change the left side to greater than ( > ) and keep the right side as is.

Replace the 0 with the loop variable.

On the right side where it says 0 === 0 change the left 0 with “after” and replace the right side with “before”.

Go back to the variable tab and select the “set after to 0 blocks” and place two underneath the “loop until block”.

For the first one change, the “after” to “before” and for the one underneath it change the “after” to “loops” and set the number to one.

Now delay it for 1.2 seconds.

Now we are gonna make it so it makes a sound and light if the player is either or wrong or right.


Take the if true then block and place it underneath the loop until block.

Put the 0===0 block inside the true space. Change the left side to answer and the right side to puzzle.

Then go to the sound and select the “play random sound and wait”, change the random to the achievement sound under the game section. This would be the sound that will play if the player succeeds.

Change the wait to continue by tapping it.

Now we are gonna make the sphero turn green by going to the light section and grabbing the strobe for block and changing the colour to green. Then change the time to 0.2 seconds and change the 0 to 3 making the sphero blink green light for 3 seconds.

Now put main led to black so it won't show a different colour.

Do the same if the player fails but change the sound to fail and instead of green change it to red.

Now were are going to create a new block group.

Select the event section and drag the freefall block anywhere in the space of the screen. This will indicate to do a certain program while the sphero is in the air.

Go back to variables and drag the set ___ to ___ block and set it to answer.

Now go to operators and get the 0 + 0 block and put it inside the right side of the set block.

Get the “answer” variable and put it on the right side of the block of the “0+0” block.

Now get the main LED block again and change it to blue and connect it with the set block.

Go to the sound bar and choose “play random sound and wait”.

Replace random with the nudge sound.

Delay it for 0.5 seconds.

Lastly, connect the main LED block to the delay block and change it to black.









Image result for sphero edu ball























This is what it should look like



Instructions of the game:
The instruction of the game is simple, once the start button is pressed, wait for the Sphero to blink, simultaneously count how many times it blinked, the number that's been counted should be the same amount, Sphero is tossed to succeed in the game.

What did you learn?

I learnt how to code not just in the computers but taking coding into real life. I was also informed about the Sphero Edu app and it's function, creating a programme to create a game, adjust the lights and sounds for a robot to follow.

What will you do next time?

If I got the chance to do this again, I would advise myself to do something simpler, so I won't have to be stressed out on coding.





       



1 comment:

  1. Hello Sofia, I like how you have photos of the codes you've done. Maybe next time you could fix your sentences so it doesn't go out of the post.

    ReplyDelete

Note: only a member of this blog may post a comment.