Design and Testing

The PiCalc app features a simple, user-friendly calculator that features the four basic arithmetic operations: add, subtract, multiply, and divide. PiCalc supports both integer and decimal operands, while also allowing for continuous operations using previously calculated results, as would be expected of a fully capable four-function calculator. The design and testing steps involved in implementing PiCalc are described below.

Design steps for this app consisted of using the appropriate PyGame functions to display the desired calculator screen and operand/result states, implementing and optimizing the touch input detection on the various buttons, and performing all necessary bookkeeping required to maintain the necessary operands and produce the correct calculator outputs. PiCalc's design exhibits modularity by having separate, contained functions for drawing to the screen and both press detection and bookkeeping. With respect to the PyGame display functions, we used a combination of the text-drawing and rectangle-drawing capabilities. Text was used to indicate the digits (0-9) or operators (+, -, x, /, clear, =) to which each calculator button corresponded. A rectangle was used at the top of the screen to demarcate the operand entry/calculator result display number. A dedicated function was implemented to handle all display update aspects of PiCalc, using maintained variables for the current operand or output to be displayed. For touch input detection, we implemented a dedicated function to check any press that occurs while in the PiCalc app. In terms of registering the initial detection of a full touch screen press, we use the Pygame event detect functions that return the position of a touch press, which we then pass in to our check function.

At any given time, we maintain a minimum of four variables: one for each of the arithmetic operands, one for the operator, and the final variable for the calculated output. The key design decision we made that facilitated our simple design was to always maintain the numeric value variables as strings instead of numbers. This made it particularly easy to implement operand inputs, since we simply needed to append the most recent user input press (character) to the currently-maintained operand string. Upon a user press of one of the four arithmetic operators, we register this in a dedicated variable and switch to the mode in which the user may now enter operand two. Finally, upon pressing the '=' button, the appropriate output is calculated and stored in the output variable, which is then displayed by PiCalc in the console box. Pressing 'C' results in all four of these variables being cleared. Alternatively, if the user now presses another operator button, the current output is moved into operand one, the operator variable is updated with the appropriate action to be performed, and the user is now able to enter operand two for the next calculation. The biggest challenge with the PiCalc design stemmed from ensuring all buttons fit on the screen with enough space for distinguishable event detection. With a little experimentation, we were able to achieve a successful display layout that maximized both ease of use and aesthetic appeal.

Figure 1: Desktop testing of PiCalc

Testing for PiCalc consisted of user testing to verify the touch detection accuracy as well as the correct calculator outputs. First, all touch detection needed to be confirmed to be working as expected. This was done by temporarily setting the appropriate environment variables in order to run the app in a console on the startx Pi desktop, which allowed for precise clicks with the mouse to be observed in order to confirm functionality. An image from this process can be found in Figure 1. We also performed extensive user testing to confirm the calculator was functioning correctly. One thing we ended up forgetting to address in the first implementation was the division by zero case, which we then handled by automatically clearing all entries in this case.


Results

The results are that PiCalc is a fully-functional basic four-function calculator app that supports continuous operations on both integer and decimal numbers. Figure 2 and Figure 3 illustrate a couple of instances from the PiCalc operation on the piTFT screen setup. Furthermore, since results can even be displayed in scientific notation, the calculator output has an extremely wide range, and operation is simply limited to how many digits will fit on the screen for the user-entered operands.

Figure 2: PiCalc Operation Example

Figure 3: PiCalc Operation Example with Scientific Notation