How to Code a Vault With Mircobit.
by Zushya in Circuits > Gadgets
393 Views, 1 Favorites, 0 Comments
How to Code a Vault With Mircobit.
What is a Micro bit?
So, you may wonder, "What even is a Micro bit, and how can I use it?" Well, it's extremely simple. A Micro bit is a small device that allows the user to display different images on the five by five screen. It also can be connected to different devices such as a micro servo. Today we will be using Tinkercad to code our micro bit to display numbers and unlock a door.
Supplies
- 1 Micro Bit
- 1 Micro Servo
- Wires
- Alligator Wires
Connect the Micro Servo to Micro Bit
To start off, grab the micro bit and servo and the wires. Then you will want to Connect the Signal port, on the micro servo, to the 0 clip on the micro bit. In Tinkercad the alligator wires will connect to the servo but if you create the vault, you will need to use wires to then attach to the alligator wires. After connecting the signal port to the micro bit, connect the Power port to the 3V and the Ground port to the ground on the micro bit.
Code the Display Numbers
Here's the hard part, you will have to block code a password for your vault. Mine is eleven and you may use mine if you want to. First, you will start of with a On x Pressed input and insert a image or a text. After that, add a When Pressed block. It is important that you hold the button until the number shows. Now the rest of the code will go inside the When Pressed block. After this make a variable and place a Set Variable to 0. Now put a Repeat x block and set it to five. Then add the four following blocks: Wait: .5, Show variable, Wait: .5, Clear screen. Now think of a number that can be made in 5 turns with only three combinations. Now Place 2-3 If x Pressed blocks and make them Button A, Button B, and optional Button A+B. Place 2-3 Set Variable blocks and with a math equation in them so that you can make the passcode in the X turns. It's important to know that if you use the A+B button, it will use A and B and then the command. If this all goes to plan, it should look like this. Then add a Show number block with the variable and then a Wait .5 block.
Checking Password.
Now our vault needs to check if the code is correct. We'll start of with an If x=y statement with x being the variable and y being the targeted number. The Micro bit will check if the number is correct and then play the following blocks: Show Icon (Checkmark), Wait .5, Rotate Servo to 0 degrees. It should look like this.
If Time Is Up
Let's Make the Incorrect code for the vault. If the x amount of turns you get runs out and it's not the number, it will display a X. Here's how to do it. First put an If x then block Outside the Repeat X block. Then put an Or Math block with the two other math blocks being variable < variable-1 and variable> variable+1. It should look like this. Now the code is complete!
It's Up to You
Now you should make your case for the money you want to secure. If you need a boost, Here is the start to the vault for Tinkercad 3d Model. Hope you had fun!