Project: A Micro:bit calculator

Using a 4×4 keypad and a 16×2 LCD screen, can you construct a simple calculator?

Step 1: Connect up the hardware. Review the notes on keypads and LCD screens, make sure you understand how they work, connect them up and run some test programs. Both should be able to connect to pins 19 and 20 (the I2C pins) and operate independently.

Step 2: Can you make what you type appear on the screen, one character at a time? What about using * to clear the screen?

Step 3: Start with a very simple calculator that will accept a single digit, use A-D for +,-,x and รท, then calculate on the second digit pressed. Show the input on the top line and the answer on the second. Tip, you will find the function int(string) useful for converting strings to integers.

Step 4: Make the calculator more advanced. Allow you to put in multiple digit numbers, then use the # key for an =. You will need to break down the string into variables for each part. There is a list of string functions at w3schools. What might be useful is the split() function. Remember you can make a note of which operator is used as it is pressed. This avoids having to search the string for operators, or you could use the find() function.

Leave a Reply

Your email address will not be published. Required fields are marked *