Game Controller Lesson Three Buttons Button How its
Game Controller Lesson Three
Buttons Button How it’s connected Joypad Up P 8 Joypad Down P 14 Joypad Left P 12 Joypad Right P 13 Fire SW 1 P 15 Fire SW 2 P 16
Lights 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
Turn Light 1 Red
Move Right Algorithm • When the right button is pressed: move the light to the right Algorithm • Set Current. Position = 0 When the right button is pressed: Change the Current. Position by ? 1
Algorithms When the up button is pressed: Change the Current. Position by ? Set the Current. Position light red Show the lights When the left button is pressed: Change the Current. Position by ? Set the Current. Position light red Show the lights When the right button is pressed: Change the Current. Position by ? Set the Current. Position light red Show the lights When the down button is pressed: Change the Current. Position by ? the Current. Position light red Show the lights
Algorithms When the up button is pressed: Change the Current. Position by -8 Set the Current. Position light red Show the lights When the left button is pressed: Change the Current. Position by -1 Set the Current. Position light red Show the lights When the right button is pressed: Change the Current. Position by 1 Set the Current. Position light red Show the lights When the down button is pressed: Change the Current. Position by 8 the Current. Position light red Show the lights
New Algorithm • When the right button is pressed Clear the Current. Position light Change the Current. Position by 1 Set the Current. Position light red Show the lights
Move Right
Latest Algorithm • When the right button is pressed IF Current. Position + 1 is less than 63 THEN Clear the Current. Position light Change the Current. Position by 1 Set the Current. Position light red Show the lights END IF
Buzzzz • When the right button is pressed IF Current. Position + 1 is greater than 63 THEN Clear the Current. Position light Change the Current. Position by 1 Set the Current. Position light red Show the lights ELSE Turn the motor on Pause for 1 second Turn the motor off END IF
Code
Code
Challenge Algorithm • • Set Current. Position to 0 Turn the Current. Position light red Set score to 0 Display the score on the micro: bit Set Ball to 10 Turn the Ball light blue Forever: – When the red light reaches the Ball • • • Change the score by 1 Display the score on the micro: bit Set Ball to a random number between 0 and 63 Turn the Ball light blue Show the light
- Slides: 14