< Creating Apps with Devices (micro:bit) ('23-'24)

Lesson 5: Board Events

45 minutes

Overview

This lesson transitions students from considering the micro:bit as strictly an output device and instead introduces the buttons as tools for input. Starting with the hardware buttons, students learn to use onBoardEvent(), analogously to onEvent(), in order to take input from their micro:bit.

Question of the Day: How can the user interact with the micro:bit for input?

CSTA K-12 Computer Science Standards (2017)
    • 2-AP-13 - Decompose problems and subproblems into parts to facilitate the design, implementation, and review of programs.
    • 2-AP-17 - Systematically test and refine programs using a range of test cases.
    • 2-AP-19 - Document programs in order to make them easier to follow, test, and debug.
    • 2-CS-01 - Recommend improvements to the design of computing devices, based on an analysis of how users interact with the devices.
    • 2-CS-02 - Design projects that combine hardware and software components to collect and exchange data.
    • 2-CS-03 - Systematically identify and fix problems with computing devices and their components.

Agenda

Objectives

Students will be able to:
  • Use a board event handler to control buttons on the micro:bit

Preparation

  • Prepare a board and USB cable for each pair of students
  • Check the "Teacher's Lounge" forum for verified teachers to find additional strategies or resources shared by fellow teachers

Links

Heads Up! Please make a copy of any documents you plan to share with students.

For the teachers
For the students

Vocabulary

  • Input - the information computers get from users, devices, or other computers

Teaching Guide

Warm Up (5 minutes)

Board Inspection: Inputs

Distribute: Pass out a board and USB cable to each pair of students. Let students know that they should not yet plug the boards in.

Prompt: Ask pairs to spend one minute looking over the board, focusing on potential input devices. Based on what you already know about this board, how do you think you might use it to get input?

Share: Have groups share back their thoughts to the whole group, keeping track of ideas on the board. Push students to support their ideas with evidence from reviewing the board, but don't worry about ensuring correctness at this point.

Discussion Goal: Students will probably notice the buttons on the micro:bit. If students don’t address these, be sure to bring them up. Students may also ask about the small pads on the bottom of the micro:bit, or they may notice the wording on the back of the micro:bit saying "accelerometer" and other sensors. These sensors are types of inputs that are discussed in later lessons - if students bring these up, acknowledge them but also let students know we’ll investigate these more in future lessons.

Remarks

So far, we've only learned how to control the output from the miocro:bit. Today, we'll learn how to use the inputs on the micro:bit, like the buttons. Inputs are how the device gets information from the user.

Vocabulary:

  • Input: the information computers get from users, devices, or other computers

Activity (35 minutes)

Transition: Send students to Code Studio

Teaching Tip

Guide to Programming Levels: Additional guidance for programming levels is provided in the Guide to Programming Levels. This document includes strategies and best-practices for facilitating programming levels with students.

Troubleshooting Devices: If student devices aren't able to connect, they can click the Help and Tips tab and then access the Maker Setup page (click the image to see more). This will let them re-reconnect their board to App Lab.

If students continue to have issues, refer to the Troubleshooting section of our Maker Support Article

Discussion Goal: This code uses an event to detect user input, but it waits for an event on the micro:bit instead of the screen. When students run the code, nothing will happen until they press the A button on their micro:bit. Once they do, the an LED on the ledScreen will light up.

Assessment Opportunity

Formative Assessment: This level can be used as a formative assessment. A rubric is provided in the level, and written feedback can be given to students. Click here to learn more about giving feedback to students.

Wrap Up (5 minutes)

Journal 3-2-1

  1. What are two types of board events you have seen so far?
  2. Describe two different situations and how they would need two different events.
  3. What's one other event you haven't learned yet, but you think might exist?

Discussion Goal: Students should make reasonable choices for when one board event might be better than another. You may want to have a short class discussion before or after this journal prompt to highlight the advantages and disadvantages of each event type.

Creative Commons License (CC BY-NC-SA 4.0).

This work is available under a Creative Commons License (CC BY-NC-SA 4.0).

If you are interested in licensing Code.org materials for commercial purposes contact us.