Introduction: Microbit Running Assistant With Magic 8 Ball
We are going to code Running Assistant with Magic 8 Ball,
A Microbit running assistant is a great help for people who used to run a lot, for people who run sometimes or even for people who just started running. Sometimes you need to make decisions, for example- To decide, which way to continue going, and for that we have Magic 8 Ball. This Instructable is divided into 10 parts.
Note: Each step will have picture to detailed the steps you needto follow for making the code.Please read through, the whole instructable before start doing it. () Brackets in this Instructable are words and parts which are important. So () brackets are just a way of showing, the shape of the word, that rounded shape. So I hope, you guys don't get confused.
Step 1: How to Start!!
Firstly go to your search webpage and search for https://makecode.microbit.org, which takes you to the home page, to code Micro bit. Then you will see Headline (My Project) in black colour, and underneath it, you will see an option in Violet which will be showing (New Project) select it and the start page will pop in!
When on the start page, you will find (Start) and (Forever) already placed.
Step 2: Let's Start Coding!!
2) Now we are going to code a starting line with a smiley, which will be displayed whenever you start your Microbit. So right click on the (advanced) option and search for (Images) in (Images), search for (Show image myImages at offset 0).
Then fit it inside the (on start) coloumn, then go back to (Images) and while scrolling down find (icon image), when you found it drag it and put it on (myImages) of (Show image myImages at offset 0). Then change the image icon from(heart) to a (smiley) You could even change it to whatever you like!.
Then go to (Basic) option, which is the first option, and select it. When in (Basic), find (show string“Hello”), which will be our starting intro. Then fit it inside the (on start) block under (Show image icon image at offset 0). You could even change the intro to something else, for example (Hello Sir/Madam).
Step 3: Coding...
3) The Step Counter: Now we have to make a (Variable).So you have to find (Variable) which is underneath (Logic) and is stated in colour Red. When in (Variable) you will see a box naming (Make a Variable...), select it and a box will pop out stating (New variable name:) as shown above.
Type in (Step) as a name of the (Variable), and then press (ok). Now you will see three options, but you are gonna select the one saying (Set (step) to (0)),which is the second option. Then drag and fit it to the (on start) block. Also don't forget to put the (Set (step) to (0)) underneath all others in (on start) option.
What (Set (step) to (0)) does is that, it sets the starting step number which is, of course zero.
Note:- Variable are basically things microbit have to remember.
Step 4: Still Coding...
4) Now we are going to code, how the counter is gonna detect our step. So go to (Input) and there you will see a block naming (On shake) drag it out and place it somewhere on the page. Then you are gonna go back to (Variable) and then drag the option saying (Change Step by 1 ) and fit it inside the (On shake) block. So that whenever we shake our feets, it counts or add 1 to the current number.
Step 5: Halfway Done...
5) Now we need to know how many step so far! So for that go to (Basic) and search for (Show Number). When you find it drag it out and fit it inside the (Forever) Block. Then you’re gonna go back to (Variable) and select the option saying (Step). Then you're going to put the (Variable) Step instead of 0 in the ( Show number 0 )block. So it Becomes (Show number Step).
Step 6: Again Coding...
6) There can be a display lag, so that the number is being displayed late, and you may even miss some of your step just because it is being displayed late. So for that you are gonna go to the (Search) option, which is the top option in the option bar. Then you are gonna type in (Stop animation) when you find it, drag it to (on shake) and fit it inside it.
Also it is not important that you put (stop animation) under (Change (Step)by (1)) because it just dosen't really make any difference. But I like it to be always under, because then it becomes even clear.
Keep in mind to seperate all of the options, so all of your options on the page dosen't look crushed up together.
Step 7: A Bit More Coding...
7) Now go to (Input) and find (on button A pressed)and place it somewhere on the page. Afterwards left click on (A) of (on button A pressed) and choose (A+B).
Then go to (Variables) and select the option saying (Make a Variable...) and name it (Answer) and then select (Ok). Now from the three options take (set (answer) to (0) and put it under (on button A+B pressed). Now go to (search) option and search for (pick random 0 to 10) you could even find it on (Maths) option. Now put (pick random 0 to 10) instead of the 0 of (set answer to 0). Now select (10) from (pick random (0) to (10) and change it to (3). So it becomes (pick random (0) to (3)
Step 8: Almost Done...
8) Now go to (Logic) and search for (If then else) andthen drag it and put it under (pick random 0 to 3) in (on button A+B presssed). Now go to (logic) and take out (0 = 0) and then put it on the (True) of the (If then else) as shown on the first picture.
Afterwards go to (Variable) and take (answer) from it and drag it to the first zero of (0 = 0), later go to (basic) and choose (show string "Hello") and drag it under (if answer = 0 then) and type in (No way!) in the string. Now press the (Plus) button 3 times of (If then else), which is on the down left corner. And press once the bottom minus sign, which is on the right hand side. Then it should look like that you have 3 six sided shape.
Now duplicate (answer = 0) three times and put one in each of the six sided shapes. Now in the second (answer =0) from top, change it to (1) from (0), on the third one change it to (2)from (0) and on the fourth one change to (3) from (0).
Now go to basic and find (show string) and put it under the (answer (=)1) and write (Probably!) in the string, by changing it from (Hello). Now duplicate the (show string) 2 times by right clicking it and put it under each (else if then). On the third string, type in (Unlikely!) instead of (Probably!) and on the last string type in(Definitely!) and at last it should look like! as shown above!
Don't forget to ask a question to the Magic 8 Ball before pressing (A+B).
Step 9: Last Adding...
9) Now we are going to add some music- Firstly go to input and search for (on button A pressed) and place it somewhere on the page. Also don’t forget to change (A) to (b) by left clicking on (A) of (on button A pressed). Now go to (Loop) and find (Repeat 4 times do), and drag it to (On button B pressed). Now go to (Music) and find (Start melody (Dadadum) repeating (once)) then drag it out. Then duplicate it four times by right clicking on (Start melody (Dadadum) repeating (once)). So that you have five (Start melody (Dadadum) repeating (once)) now fit all of the melodies inside (Repeat (4)times do) in (On button B pressed).
Then left click (Dadadum) and select the first melody to (power up) and by continuing second one to (power down), third one to (jump down), fourth one to (jump up) and fifth one to (punchline). It can happen that you need to scroll down to find these melodies. Also don’t forget to change the repeating option to (10) from (4) of (Repeat (4)times do). And to put the repeation of the (Melodys) to (forever) by left clicking on (Once).
Note- this is only a suggestion, so you can build your melody by selecting different melodies and mixing them together. At last it should look like as shown above.
Step 10: Enjoy...
10.0) At last the whole page should look similar to the picture shown above. Now by clicking on (Download) option you can download your program to your Micro Bit. By dragging the Hex file to the Micro Bit or even move the Hex file to the Microbit, but the Microbit firstly should be connected through the USB cable. Then you’re good to go, and again you can add more stuff if you want to!