Love Meter

Introduction

How much love ๐Ÿ˜ are you emitting today? Create a ๐Ÿ’“ LOVE METER ๐Ÿ’“ machine with your micro:bit!

Love meter banner message

Step 1

Weโ€™ll use this ||input:on pin pressed|| block to run code when pin 0 on the micro:bit is pressed. From the ||basic:Basic|| Toolbox category, drag a ||basic:show number|| block and drop into the ||input:on pin pressed|| block.

input.onPinPressed(TouchPin.P0, function() {
    //@highlight
    basic.showNumber(0)
})

Step 2

From the ||math:Math|| category, get a ||Math:pick random|| block and drop it into the ||basic:show number|| block replacing 0.

input.onPinPressed(TouchPin.P0, function() {
    //@highlight
    basic.showNumber(randint(0, 100))
})

Step 3

Now letโ€™s be sure to label our Love Machine! From the ||basic:Basic|| Toolbox category, drag an ||basic:on start|| block and drop it anywhere on the Workspace. Then get a ||basic:show string|| block and place it in the ||basic:on start|| block. Type the words โ€œLOVE METERโ€ into the ||basic:show string|| block.

//@highlight
basic.showString("LOVE METER")
input.onPinPressed(TouchPin.P0, function() {
    basic.showNumber(randint(0, 100))
})

Step 4

Letโ€™s test our code. Press Pin 0 on the micro:bit on-screen simulator (bottom left). Numbers between 0-25 = ๐Ÿ–ค No Love, 26-50 = ๐Ÿซถ BFF Love, 51-75 = ๐Ÿ’˜ Brokenhearted Love, 76-100 = ๐Ÿ’–๐Ÿ”ฅ Fiery Hot Love!

Step 5

If you have a micro:bit device, connect it to your computer and click the |Download| button. Follow the instructions to transfer your code onto the micro:bit. Once your code has been downloaded, hold the GND pin with one hand and touch the 0 pin with the other hand. Your micro:bit ๐Ÿ’“ LOVE METER ๐Ÿ’“ machine will detect the love current flowing through your body!

randint(0, 100)
# BlocksExistValidator
input.onPinPressed(TouchPin.P0, function() {})