Micro: bit-> evaluate your friendships [Full Guide]

micro-bit-featured two previous articles had proposed you to discover the micro: bit and how to use . But what can we do with this card?

Let’s learn to code our micro: bi t to give you a grade of compatibility with your friends.


how to?

step 1: coding buttons

Let’s make a small program that allows to simulate a test of friendship based on random numbers. When the buttons A and B will be supported at the same time, the micro: ILO will appear on the screen a flashing question mark 5 times. A random number will appear. The higher the number the more you “friends”. For a number above 75, micro: ILO will also display a heart.


(Vous pouvez utiliser dele de texte défilant à la place d’une image si vous préférez.)

  • Add a new onPressAandB to your project.


  • add to the code a question mark for 1 second, to give a bit of suspense.


  • test the code: when you press the buttons A and B together , a question mark should be flashing on the screen.

step 2: display a note

view the note of friendship to the screen.

  • click the “Globals” library, and create a new variable called rating .


  • drag your variable at the end of your onPressAandB .


  • click the library “ random ‘, and use the random block to settle to a random number between 0 and 100.


  • Add a say like this:


  • Finally, after a delay, show again the instructions.


  • test your code. Now, if you press the buttons A and B together, random notation should be displayed.

step 3: best buddies

we will display a heart when 2 friends have a high rating.

  • Add a if to your code, just before the instructions are displayed.


  • you want to display a heart if the score is high (say over 75). To do this, click on the arrow down in your if .


  • drag your variable rating in the left side of your if , and add the number 75 on the right side.


all code in this if will be executed if the score is more than 75 .

  • show an image of the heart on the screen for 1 second if the note is over 75.


  • test your code. Is the image of a heart is displayed if the note is more than 75? You will probably need to test several times!

challenge: low score

can you display a cross or a sad face for a score under 25?

step 4: adding an animation

display a short animation in your program.

  • here is the code to display a question mark for 1 second before clearing the screen:


  • so that this exclamation mark flashes 5 times, you will need to put this code inside a loop for.


  • , you will just need to set the loop to start at 1 , and finish at 5. This will allow the repetition of code 5 times in a row.


challenge: more animations

can you make Flash other images on the screen?

final code

 / / When the BBC micro: bit runs.function onStart () microbit.draw (Pattern ("00000.01010.10001.01010.00000"));

function onPressAandB () for (var i = 1; i 75) microbit.draw (Pattern ("01010.11111.11111.01110.00100"));

wait (1000);

microbit.clear ();

wait (1000);

microbit.draw (Pattern ("00000.01010.10001.01010.00000"));


help video

Article inspired by: https://href.li/?https://www.codeclubprojects.org/en-GB/microbit/rate-your-mates/

No comments:

Powered by Blogger.