MicroPython 101

A project-based introduction to micro:bit programming using MicroPython with instructions to build 16 hands-on micro:bit projects. Request Quote

  • Grades 6 - 8
  • 14 lessons
    • Web
  • Python
  • Advanced Course
Course includes
  • 14 lessons
  • 86 activities
  • Enhanced Creativity Tools
  • Automatic Assessment
  • Tutorials and Reviews
  • Coding Puzzles
  • DIY Projects
  • Quizzes
  • Teacher Guides
  • Answer Keys
Prerequisites
No previous coding experience required.

MicroPython 101 Lesson Plan

Lesson: Button Masher
Time: 45+ mins

Introduction

Who's ready to mash buttons? In this lesson, students will learn how to program a 2-player game using their micro:bit! Additionally, they'll learn how to create a progress bar so each player can see their status during the game. How to play: Two players will use one micro:bit. One player will use button A, while the other player will use button B on the micro:bit. The players will repeatedly press their button as quickly as possible. The first player to reach 50 clicks wins!

Note: The show_progress() function is Tynker specific. If students try using this function in Python projects beyond the MicroPython 101 course, it will not work.

New Code

  • show_progress() : This is a function that takes two arguments and displays two progress bars (one on the left and one on the right side) on the micro:bit.

Vocabulary

  • None

Objectives

Students will...

  • Use the micro:bit to run coding examples
  • Apply coding concepts to solve challenge activities
  • Create a two-player game using the micro:bit

Materials

  • micro:bit device (recommended 1 per student)
  • USB cable
  • Computers, laptops, or Chromebooks (1 per student) with student account access to Tynker.com

Warm-Up (5 minutes)

  • Ask students to answer these short response questions:
    • What has been your favorite project so far?
    • What is something you struggle with in the MicroPython coding activities?
    • What game or program would you like to program using your micro:bit?

Activities (45 minutes)

Facilitate as students complete all Button Masher modules on their own:
1. Button Masher! (Document)

  • Students will read a short document that introduces the lesson.
  • Students will learn that they're going to build a two-player game using one micro:bit.
  • How to play: Each player will have their own button to press (either button A or button B). The goal of the game is for each player to press their own button as quickly as possible. The player who presses their button 50 times the fastest wins!
  • Make sure students analyze the video to see what their game should look like.

2. Registering Clicks (DIY)

  • In this module, students will begin programming their game. Explain that they'll continue adding onto their game in the upcoming modules.
  • Coding Challenge, Step 1: Counting Clicks
    • To solve this challenge, students need to program their micro:bit to count the number of times the user presses each button.
    • Make sure they read the requirements carefully.
    • Give a hint: Ask students…
      - What should we name our variables? (Answer: score_a and score_b.) After we name our variables, what value should we assign it to? (Answer: We need to assign it a value of 0.)
      - What operator should we use to increase the variable? (Answer: The += operator.)
      - If we want to display player 1's variable, what needs to go inside the display.show() parameter? (Answer: score_a )
      - What function should we use to pause our program for a specified amount of milliseconds? (Answer: sleep() )

3. Displaying Number of Clicks (Example)

  • Students will read a short document that explains that they can create graphics to represent a progress bar on their micro:bit. As the player continues to press their micro:bit button during the game, the progress bar will continue to fill.
  • Point out to students that their 2-player game only requires one micro:bit.
  • Make sure students are trying the "Example 1" activity, which provides them completed code to display a progress bar on their micro:bit.

4. Showing Progress (DIY)

  • Students are introduced to the show_progress() function, which takes two arguments (e.g., score variables). Point out to students that this function allows them to display two progress bars (one on the left and one on the right side) on the micro:bit.
  • Coding Challenge, Step 2: Displaying the Progress Bar
    • To solve this challenge, students need to delete part of the given code (as noted with the comment "#Replace this code"). Next, they'll need to replace the deleted code with a show_progress() function and type the correct variables (e.g., score_a and score_b)

5. Finishing Touches (DIY)

  • Coding Challenge, Step 3: Finishing the Game
    • This is the last step for the game. Make sure students read the criteria carefully.
    • Give a hint: Ask students…
      - What do we need to do in order to display a "Get Ready" message? (Answer: Use a display.scroll() function with the following parameters: ("Get ready!!!", wait=True, lop=False) ).
      - What do we need to do in order to flash the screen? (Answer: Use a display.show() function with an image string.
      - If we want the loop to end when either variable is greater than 50, we need score_a and score_b to be less that what value? (Answer: 51.) Part of their solution might look similar to this:

6. Playing the Game (DIY)

  • This module instructs students to experiment with their code as they test and debug their game
  • Point out to students that each time a player presses their button 5 times, the progress bar should increase by 1 LED.
  • If students finish early, ask them to try the bonus activities:
    • Do they need help increasing/decreasing the amount of clicks? Ask them to change the number "51" in their code to a different value. For example, if they want to end the game after 20 clicks, part of their solution might look like this:

  • Optional: Ask students to experiment with their code and create their own game rules.

7. Review

  • This module reviews the following:
    • Students can use strings to create a progress bar to track two players' progress at the same time.
    • The floor division operator, //, can be used to discard the remainder of a number.

8. Quiz (Multiple-choice)

  • Students will be asked 5 quiz questions to review concepts from this lesson.

Extended Activities (10 minutes)

Lead a discussion with your students:

  • Who can give an example of a variable? (Example: score_a = 0)
  • What function allows you to remove images from your micro:bit? (Answer: display.clear() )
  • True or false: sleep() uses milliseconds, not seconds. (Answer: True.)

U.S. Standards

  • CCSS-Math:MP.1
  • CCSS-ELA: 6-8.RST.3, 6-8.RST.4, 6-8.RST.7
  • CSTA: 2-AP-11, 2-AP-13, 2-AP-15, 2-AP-17
  • CS CA: 6-8.AP.11, 6-8.AP.13, 6-8.AP.15, 6-8.AP.16, 6-8.AP.17
  • ISTE: 1.c, 1.d, 4.d, 5.c, 5.d, 6.b

U.K. Standards

Key Stage 2 (Years 4-6)

  • Design, write and debug programs that accomplish specific goals, including controlling or simulating physical systems; solve problems by decomposing them into smaller parts.
  • Use logical reasoning to explain how some simple algorithms work and to detect and correct errors in algorithms and programs.
  • Understand computer networks, including the internet; how they can provide multiple services, such as the World Wide Web, and the opportunities they offer for communication and collaboration.
  • Use technology safely, respectfully and responsibly; recognise acceptable/unacceptable behaviour; identify a range of ways to report concerns about content and contact.

Key Stage 3 (Years 7-9)

  • Understand several key algorithms that reflect computational thinking [for example, ones for sorting and searching]; use logical reasoning to compare the utility of alternative algorithms for the same problem.
  • Create, re-use, revise and re-purpose digital artefacts for a given audience, with attention to trustworthiness, design and usability.
  • Understand a range of ways to use technology safely, respectfully, responsibly and securely, including protecting their online identity and privacy; recognise inappropriate content, contact and conduct and know how to report concerns.