Name: Ong Aaron Course/Section: BSME III-GM Set B
Name: Ong Aaron Course/Section: BSME III-GM Set B
Name: Ong Aaron Course/Section: BSME III-GM Set B
SET B
Activity 3 – Arduino Calculator. Create a simple calculator using the keypad. Using letters ABC and D as
basic operators A = Addition, B = Subtraction C = Multiplication and D = Division. A sample structure is
provided. If an error is encountered, encircle the statement to be corrected and write the correction on
side.
};
long first = 0;
{
char keys[ROWS][COLS]= {
Serial.begin(9600);
{'1' , '2', '3', '+'},
}
{'4' , '5', '6', '-'},
switch(customKey) total=first*second;
{ Serial.println(total);
Serial.println(first);
Serial.println("+");
first=0; second=0;
Serial.println(total);
break;
first=0,second=0;
break;
case '-':
Serial.println(total);
}
first=0; second=0;
}
break;
long SecondNumber()
{
case '*':
while(1)
first = (total !=0?total:first);
{
Serial.println("*") ;
customKey= customKeypad.getKey(); }
{ }
Serial.println(second); }
CONCLUSION
What are the types of pin you used? Explain why you chose them. What function and structure of
your program is essential in resolving the given problem? How?
The switch statement was necessary since it allocates a case based on the keypad button pressed. When
a specific button is pressed, the switch statement starts a loop that performs the arithmetic operation
that was assigned to that button. Furthermore, by employing the switch statement, the problem
became easier to code and comprehend. Using the function SecondNumber(), on the other hand, made
the program easier to code because it eliminated the need to create a code for getting the value of the
second integer in the arithmetic operation. Additionally, the while loop in the SecondNumber() function
is required for receiving and processing the second number's input as well as waiting before pressing the
'=' button.
1. Switch Statement
2. While Loop
3. SecondNumber ()