Micro: bit-> Sayer of good adventures

you are going to program your micro: bit for her to read the future! Just ask him a question, and press a button to give you the answer!

translation of ARTICLE

Let’s start with instructions on your micro scrolling: bit.

  • to add a bit of text, click the arrow, and then choose ‘ String ‘.

  • add your instructions in the text box.

here is what your code should look like:

  • test your code: you can test in the editor or on the microphone: bit himself.

  • the text of your blocks say should rather slowly cross the screen. To speed it up, you will need to use a version blocks say .

delete your block say , your for onStart is empty.

  • click on the arrow next to the block say and you will see a second block. Drag this block in the onStart .

  • this version of say allows you to decide the time to wait (in milliseconds) of the scroll. Type 10 in the text box.

save your project

If you retest your code, you will see that this time, the text scrolls too quickly. Can change you the number of milliseconds in your say block so that the text scrolls at a good speed?

save your project

recognize that your microphone: bit may make a decision by choosing at random a number (0 for no and 1 for Yes).

  • Add a new event onPressA to your code.

  • we will create a new variable to store the response. Click the ‘Library’, then click ‘Globals ‘.

  • click on the + to create a new variable called answer .

  • drag your new variable in your onPressA .

as you can see, the = in the block means that you can set the response to display.

  • click the ‘Library’, then click ‘Random’.

  • drag the block of Random number ( random number ) on top of the Word update.

  • here is what your code should look like:

  • then you want to display the word not on the microphone: bit only if the response ( answer ) is 0.

to do this, click the ‘Language’ tab, and then drag a block if at the end of your onPressA .

  • click on the arrow down on the block if and click left == right.

  • drag your answer on the left side of the fi, and 0 in the right side.

  • all code in the if block will be launched only if answer is 0. As 0 is No, let’s add a say to report.

  • test your code.
    • sometimes answer will be 0, and the microphone: ILO should say ‘no ‘.

    • sometimes answer will be 1, and nothing will happen!

save your project

can you add code that ‘yes’ is displayed on your microphone: bit if the answer is 1? You can even change the text displayed to something more interesting than just ‘yes’ and ‘no ‘!

you could do something to your microphone: bit like ‘maybe’ or ‘Application’ again if the answer is 2. To achieve this, you’ll also need to change your code to choose a random number between 0 and 2!

save your project

can you code your microphone: ILO to make a decision when it is shaken instead of when a button is pressed?

save your project

you just create, encode, and program… A Sayer of good adventures and as they say, randomly doing things!

and of course if you need help to solve the challenges do not hesitate to leave a comment!

No comments:

Powered by Blogger.