micro:bit How-to: Code the Logo Touch Sensor

Description

This activity shows how to use the touch sensor at the top of the micro:bit. The touch sensor is disguised as the micro:bit logo and it works in the same manner as touchscreens that we see on cellphones, gaming devices, computer screens, and any application that requires a high degree of accuracy when identifying the location of the touch. It is called a capacitive touch sensor and uses the conductivity of the human body, or of the stylus that is used to touch the screen to identify where contact is made with the screen. For more on capacitive touch sensors, click here.

Programming Language

MakeCode Blocks

Difficulty Level

Beginner

Age Range

9 and up

Materials

Optional materials:

Programming the micro:bit

Develop the problem statement

This project shows how the capacitive touch sensor can be programmed, so I would write the problem statement as follows:

Create a program that shows how the Logo Touch Sensor can be used to trigger actions for the logo being touched, pressed, and long-pressed.

Write the algorithm

The algorithm can be written as:

  • When logo pressed
    • Play a note for enough time to hear it
  • When logo touched
    • Play a different note from the note played or pressed
  • When logo long-presses
    • Play a note different from the first two

Write and test the code

The sample code can be viewed here.