Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 78 - Ai Robogenius
P. 78

    STEP - 19   Add show icon block in the else section and choose the scissors icon.

                                                    on  shake

                                                     set  hand    to  pick random  0  to  2

                                                      if    hand   =     0    then

                                                       show icon

                                                      else if  hand  =     1    then

                                                       show icon

                                                      else

                                                       show icon

                                     Your block-based code will look like this.

                       STEP - 20   Click on the Shake button to run the program.

                                     You  can also download  the code  to  your  Micro:bit  by  clicking  the
                                     Download  button  in MakeCode  then connect  the Micro:bit  to  your

                                     computer and transfer the file.
                      Output

                      When the program runs, shaking the Micro:bit activates its accelerometer
                      sensor, which detects the motion and triggers the code.

                      The Micro:bit then generates a random number, 0, 1 or 2, to decide whether to
                      display rock, paper or scissors.

                                     AI RoboGenius - V
                     76

| 73 74 75 76 77 78 79 80 81 82 83 |