The goal of this lab is to introduce you to the basics of the GPIO (general purpose input/output) and serial communication modules of Mbed OS. You will implement a basic four function calculator using a 4x4 matrix membrane keypad as an input, and the serial terminal as the output.
This lab is to be completed individually, but you may consult with others if you are stuck (see the Collaboration Policy in the course syllabus).
A summary of the design requirements for the calculator are shown in the table below. All labs must implement each of these requirements for full credit. Further details for these requirements are shown below.
| Requirement | Details |
|---|---|
| Calculation | perform addition, subtraction, multiplication, and division of two integers, with the result returned as a float i.e. including fractions. |
| Keypad | A-D should correspond to +, -, *, /, respectively. * should be used for negative numbers, and # to indicate that a computation should be performed. |
| Keypad debounce | 200 ms |
| Keypad inputs | Use first input on scan; does not need to detect simulataneous presses |
| Serial monitor output | Output should appear as typed, i.e. 15x4 = 60 |
| Input validation | Required for the following cases: |
| • An operator is entered before number 1 has been entered. | |
| • An operator has been entered twice. | |
• A terminator (#) has been entered before two numbers and an operator have been entered. |
|
| • An invalid character has been pressed. | |
• The result attempts to divide by zero (this will be implemented in main.cpp). |
|
| Fractions | Show up to 3 decimal points |
| Integer overflow/underflow | Not required to accommodate |
The calculator should be able to perform addition, subtraction, multiplication, and division of two integers, with the result returned as a float i.e. including fractions.
Associated functions:
float computation(int num1, int num2, char operation);

The numbers 0–9 on the keypad should be used to enter each of the two integers, with a function pressed in between. The letters A–D should correspond to the four functions as follows: