Make: micro:bit love meter

For an upcoming day at work I’m trying to come up with ideas of what students could make with a micro:bit, a button, some lights and a servo motor.

Here we have: the micro:bit love meter!

Build

I used the following equipment. I’m not paid to advertise any of this.

Servo

The servo has three wires which end in a female connection.

  1. Plug the male end of the male to female jumper wires into each one.
  2. Plug the female end of the wires into the micro:bit edge connector pins like so:
    1. Ground (Brown) to 0V
    2. Power (Red) to 3V
    3. Data (Orange) to Pin 1

(PICTURE Coming Soon!)

Button

The arcade button has two connections.

  1. Clip a crocodile clip onto each connection
  2. Clip the male end of a male to female jumper wire to the end of each crocodile clip
  3. Plug the female end of the wires into the micro:bit edge connector pins
    1. 0V
    2. Pin 12

Neopixels

The neopixels have three pins on each side. On the side with IN written on it:

  1. Connect a female to female jumper wire to each pin
  2. Plug the female end of the wires into the micro:bit edge connector pins like so:
    1. + to 3V
    2. G to 0V
    3. In to Pin 0
  3. Chain another neopixels to the first using female to female jumper wires
    1. + to +
    2. G to G
    3. O to In

Code

Before you start you need to add the Package Neopixels by selecting “Add Package” at the bottom of the menu.

  1. Create a new variable and call it myLights (Variables > Make a Variable)
  2. Set myLights to RGB Neopixels at P0 using the block below:

lm1

You also need to set the button up using the block “set pull pin P12 to up” which you find under: Advanced > Pins

The game starts with the lights on blue.

The program is waiting for the user to press the button. Once the button is pressed a random number between 0 and 179 is chosen. The servo is then sent to that angle.

If the angle is less than 90, the user is successful and the lights go red. If it’s greater than 90 the user is not successful in love and the lights go yellow.

After 2 seconds, the servo goes back to 180 and the lights go blue again.

We do this in a forever loop as we are forever waiting for the user to press the button.

lm2

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s