PREVIEW: Now that our micro:bit is connected, let's look at an example of the kind of project you'll be making today.

  • Click Run to see a version of the game you'll create.
  • This program has a sprite that moves with the micro:bit's A and B buttons. Keep the ball from falling to the floor!
  • When you're finished, click Submit and Next to continue.

microbit = codesters.Microbit() microbit.show_string("hello") ball = codesters.Sprite("soccerball") ball.set_x_speed(5) ball.set_y_speed(5) ball.set_size(0.75) stage.set_background("soccerfield") sprite = codesters.Sprite("athlete2") sprite.move_down(140) def button_a(): sprite.move_left(50) microbit.event_button_a(button_a) def button_b(): sprite.move_right(50) microbit.event_button_b(button_b) def collision(sprite, hit_sprite): my_var = hit_sprite.get_y_speed() hit_sprite.set_y_speed(-my_var + 1) my_var = hit_sprite.get_x_speed() hit_sprite.set_x_speed(my_var + 1) sprite.event_collision(collision) stage.disable_floor()