Things used in this project

Hardware components:
magnet
×1
Microbitheart
micro:bit BBC micro:bit board
×1

Code

Full codeTypescript
Copy and paste this into the "JavaScript" view on pxt.microbit.org
let isSwitched = false
let force = 0
input.onButtonPressed(Button.A, () => {
    if (isSwitched) {
        basic.showString("B")
    } else {
        basic.showString("A")
    }
})
input.onButtonPressed(Button.B, () => {
    if (isSwitched) {
        basic.showString("A")
    } else {
        basic.showString("B")
    }
})
basic.forever(() => {
    force = Math.abs(input.magneticForce(Dimension.Strength))
    isSwitched = force > 100
})

Credits

Avatar 6et0r7jsn9
Micromonsters

We are a Dad and Daughter coding superhero duo who love to write code and build thing with the microbit

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Bikeyface Emoji Taillight (with Micro:bit)
Easy
  • 478
  • 12

Full instructions

Express yourself with your bike lights!

Make Your BBC Micro:Bit Talk Using MicroPython
Easy
  • 389
  • 8

Protip

Today, I am going to show you how to make your Micro:bit talk using a very easy programming language called MicroPython.

Display Your Name On Micro-Bit Using MicroPython
Easy
  • 353
  • 6

Full instructions

In this tutorial, I am going to show you how to code BBC micro:bit using MicroPython to display your name and other basic symbols.

Getting Started with BBC Micro:Bit
Easy
  • 928
  • 11

Full instructions

This tutorial will show you the basics to get started with BBC micro bit.

Are You in Tune?
Easy
  • 583
  • 6

Work in progress

There are many ways/apps/tools to tune an ukulele, and now there is one more!

Micro:bit Moisture sensor
Easy
  • 298
  • 4

Protip

In this quick and easy project, you build a micro:bit moisture sensor

Add projectSign up / LoginAbout BBC micro:bit