Question

In: Computer Science

Module 14: Memory, OLED and Keypads Homework Build an interactive calculator. Use the OLED Display and...

Module 14: Memory, OLED and Keypads Homework
Build an interactive calculator.
Use the OLED Display and matrix keypad to build a simple calculator application. The user presses the operands and operators using the keypad. The calculation output should be displayed on the OLED display. You may make the following simplifying assumptions.
a) Assume 1 digit numbers
b) Assume only two operators ‘+’ and ‘-’
Upload the breadboard diagram the code and a video.
Points 6: 2 points each for working and proper breadboard diagram, code and video.

Solutions

Expert Solution

Hi,

Here is the complete thing that we need, libraries that we need to include and complete code below:

Materials we need:

to make a calculator, we will need some kind of Processor, for which we can use Arduino, since this is a small project and needs large memory space for complicated code, we will use Arduino NANO.

for taking input number, we can use a 4x4 keypad with membrane switches, which has 4 rows and 4 columns, if we open up this sticker from behind, the flexible membrane PCB is visible, which has connections going from ROWS and COLUMNS to connecting pins via flexible PCB. When any membrane switch is pressed, the rows and column pins process the data as a Matrix and identify the location of key pressed.(Remember, left side pins are row pins and right side pins are column pins.)

for display we can use either OLED or LCD display, but I would like to use OLED, since the resolution of OLED is far better, we can have longer strings of numbers to operate, if we choose OLED.

Connections:

Now because we discudded above about the materials we needed, so now its the time to make connections now.

Below will be the steps for making connections:

  1. connect Keypad to any digital pins on Arduino Nano ( preferably D2 to D9).
  2. connect OLEDs SCL to Arduinos A5.
  3. connect OLEDs SDA to Arduinos A4.

  4. connect OLEDs VCC to Arduinos 5v.

  5. connect OLEDs GND to Arduinos GND.

  6. Connect a Switch between Positive of Lithium Polymer Battery.

  7. Connect Lipo to 5V and Gnd pins of Arduino.

Code and libraries requires:

Below are the list of libraries required:

  • SPI
  • Keypad
  • wire
  • Adafruit SSD1306
  • Adafruit GFX

Code:

#include <Keypad.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

const byte numRows= 4; //number of rows on the keypad
const byte numCols= 4; //number of columns on the keypad

//keymap defines the key pressed according to the row and columns just as appears on the keypad
char customKey;
double first = 0;
long second = 0;
double total = 0;
char Operator;
bool equalPressed=false;
bool showFirst = false;

char keymap[numRows][numCols]=
{
{'1', '2', '3', '+'},
{'4', '5', '6', '-'},
{'7', '8', '9', 'x'},
{'C', '0', '=', '/'}
};

//Code that shows the the keypad connections to the arduino terminals
byte rowPins[numRows] = {9,8,7,6}; //Rows 0 to 3
byte colPins[numCols]= {5,4,3,2}; //Columns 0 to 3

//initializes an instance of the Keypad class
Keypad customKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

void showSplash() {
String splashString="Arduino Calculator by";
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.setCursor(64-(splashString.length()*3),0);
display.print(splashString);
display.setTextSize(2);
splashString="Mission";
display.setCursor(64-(splashString.length()*6),16);
display.print(splashString);
display.setTextSize(2);
splashString="Critical";
display.setCursor(64-(splashString.length()*6),40);
display.print(splashString);
display.display();
delay(3000);
}

void setup()
{
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
showSplash();
display.print("Arduino Calulator By Mission Critical");
display.setTextSize(2);
display.clearDisplay();
display.display();
}

void loop(){
customKey = customKeypad.getKey();
switch(customKey)
{
case '0' ... '9': // This keeps collecting the first value until a operator is pressed "+-*/"
showFirst=true;
first = first * 10 + (customKey - '0');
showDisplay();
break;

case '+':
showFirst=true;
Operator='+';
showDisplay();
second = SecondNumber(); // get the collected the second number
total = first + second;
showDisplay();
first = total, // reset values back to zero for next use
second = 0;   
break;

case '-':
showFirst=true;
Operator='-';
showDisplay();
second = SecondNumber();
total = first - second;
showDisplay();
first = total, second = 0;
break;

case 'x':
showFirst=true;
Operator='x';
showDisplay();
second = SecondNumber();
total = first * second;
showDisplay();
first = total, second = 0;
break;

case '/':
showFirst=true;
Operator='/';
showDisplay();
second = SecondNumber();
second == 0 ? display.print("Invalid") : total = (float)first / (float)second;
showDisplay();
first = total, second = 0;
break;

case 'C':
total = 0;
first=0;
second=0;
Operator='\0';
showFirst=false;
equalPressed=false;
display.clearDisplay();
display.display();
break;
}
}

void showDisplay()
{
display.clearDisplay();
display.setCursor(110,0);
display.println(Operator);
if (showFirst) {
Serial.print(first);
display.println(first);
} else
{
display.println("");
}
if (second>0) {
display.println(second);
} else
{
display.println("");
}
if (equalPressed) {
display.println(total);
equalPressed=false;
}
display.display();
}
long SecondNumber()
{
while( 1 )
{
customKey = customKeypad.getKey();
if(customKey >= '0' && customKey <= '9')
{
second = second * 10 + (customKey - '0');
showDisplay();
}

if(customKey == '=') {
equalPressed=true;
break; //return second;
}
}
return second;
}


Related Solutions

3. Interpret calculator display: The following TI-84 Plus calculator display presents a 99% confidence interval for...
3. Interpret calculator display: The following TI-84 Plus calculator display presents a 99% confidence interval for the difference between two proportions. a. (1pt) Compute the point estimate of p1 − p2. Round to the nearest thousandth. b. (2pt) Fill in the blanks: We are 99% confident that the difference between the proportions is between ___________and_____________ . Round values to the nearest thousandth.
Complete the following Module 2 Written Homework Assignment for this module by the stated due date...
Complete the following Module 2 Written Homework Assignment for this module by the stated due date on the Schedule. Please submit in the Module 2 Written Homework Assignment folder as a .doc, .docx, .pdf or .rtf file. Instructions Complete the following questions in the form of short essays. Each question is worth 6 points. Be sure to cite your references as needed. Type all responses following each question on this assignment page and submit to the folder. All-you-can-eat restaurants allow...
Java Language Only Use Java FX In this project we will build a BMI calculator. BMI...
Java Language Only Use Java FX In this project we will build a BMI calculator. BMI is calculated using the following formulas: Measurement Units Formula and Calculation Kilograms and meters (or centimetres) Formula: weight (kg) / [height (m)]2 The formula for BMI is weight in kilograms divided by height in meters squared. If height has been measured in centimetres, divide by 100 to convert this to meters. Pounds and inches Formula: 703 x weight (lbs) / [height (in)]2 When using...
Write an interactive Java class Project8Q3, that will display a menu with the available commands 'G',...
Write an interactive Java class Project8Q3, that will display a menu with the available commands 'G', 'D', and 'X'. If 'G' is selected, prompt the user for the ID of a president to display to the screen and then display the president's information. If 'D' is selected, display all the values in the LinkedHashMap to the user with their associated LinkedHashMap key. If 'X' is selected, exit the program. The class should have the method addPresident(id, lastName, firstName, middleInitial) which...
In the interactive lecture materials for this module, you read articles and materials and watched various...
In the interactive lecture materials for this module, you read articles and materials and watched various videos, which described the history of the convergence process between the US GAAP and IFRS, including the status of convergence today. You also reviewed readings showing the differences that still exist today between US GAAP and IFRS on various accounting subjects. Below is a list of some particularly significant accounting topics or subjects where differences still exist today between the US GAAP and IFRS:...
Java-- For this homework you are required to implement a change calculator that will provide the...
Java-- For this homework you are required to implement a change calculator that will provide the change in the least amount of bills/coins. The application needs to start by asking the user about the purchase amount and the paid amount and then display the change as follows: Supposing the purchase amount is $4.34 and the paid amount is $20, the change should be: 1 x $10 bill 1 x $5 bill 2 x Quarter coin 1 x Dime coin 1...
CHE 1102 Homework #8 – Due November 14                                     
CHE 1102 Homework #8 – Due November 14                                                                                                                                                                                                   Name__________________________________                Print Two Sided or STAPLE                                                                                   Email ID ________________________________            Show work for full credit. Showing work means: 1) Write the equation you are using, 2) Fill in values (with units) in the equation, and 3) Show the final answer to correct sig figs/units. Intermediate math steps are not necessary. 1) What is the molar solubility of the following compounds based upon their given Ksp values: a)...
Hello this question is for my physics homework "display knowledge of static and kinetic coefficients of...
Hello this question is for my physics homework "display knowledge of static and kinetic coefficients of friction, and calculate one of them to solve a problem" Please answer it fast thank you
Get all homework scores for one student, calculate and display the sum of the scores, and...
Get all homework scores for one student, calculate and display the sum of the scores, and also display the word “fail” if the sum is lower than 150. Note: we do not know how many homework scores each student will enter. Ask the user how many homework scores there are at the beginning. Then, ask for a homework score at a time, for as many times as indicated by the user. C++
[7] How many MB of video memory is required to display an image with a resolution...
[7] How many MB of video memory is required to display an image with a resolution of 1,920 x 1,080 pixels and 65,536 colors (2^16colors)? However, 1 [MB] = 1,000 [kB] and 1 [kB] = 1,000 (B). [8] What is the amount of video memory required to display an image with a resolution of 1,600 x 1,200 pixels and 65,536 colors (2^16 colors)? However, 1 [MB]= 1,000 [kB], 1 (kB] = 1,000 (B). [9] Minimum required for video distribution at...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT