Skip to content
Parallax Learn

Parallax Learn

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • Making micro:bit programs

Making micro:bit programs

Pushbuttons

The micro:bit module has two pushbuttons labeled A and B, to the left and right side of the LED display. This kind of button is sometimes called a tactile switch, or tact switch for short. The micro:bit module can be programmed to respond to these buttons being pressed. In your projects, each button already exists as an object, and they can be referred to as button_a and button_b.

For example, if you want something to turn on only when button A is being pressed, you can use button A is pressed. The same can be done for button B or both A and B.

Example: is_pressed

You can make a block for each button to tell if it is pressed. The button A is pressed method will return either True or False depending on whether or not button A is currently pressed. These methods often work well with conditionals. For example, the following program displays a check mark if button A is pressed. Otherwise, it will display an X. 

  • Enter, name, and flash the project is_pressed to your micro:bit.
  • Press button A to see the display change.

Try This

  • Use the display to show the letter A when the A button is pressed.
  • Use the display to show the letter B when the B button is pressed.

Example project: on_pressed

Another commonly used method of the buttons is to run a set of blocks as soon as the button is pressed. This is what we call an interrupt because it interrupts the program to run its own blocks.

For example, the project on_pressed will display a scrolling hello when button A is pressed. If nothing is pressed, then nothing will be shown.

  • Enter, name, and flash the project on_pressed to your micro:bit.

Your Turn

  • Make a project to show a custom image for 10 seconds if button A was pressed and then disappears after.
  • Make a project to show a flash B 10 times when button B is pressed instead of button A.

Printer-friendly version

Leave a Comment Cancel reply

Count and Repeat
Prev
Making Functions
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2025 Parallax Learn • Built with GeneratePress