毕业设计 基于Arduino的计算器

0 前言

? 这两年开始毕业设计和毕业答辩的要求和难度不断提升,传统的毕设题目缺少创新和亮点,往往达不到毕业答辩的要求,这两年不断有学弟学妹告诉学长自己做的项目系统达不到老师的要求。

为了大家能够顺利以及最少的精力通过毕设,学长分享优质毕业设计项目,今天要分享的是

? 毕业设计 基于Arduino的计算器

?学长这里给一个题目综合评分(每项满分5分)

  • 难度系数:3分
  • 工作量:3分
  • 创新点:4分

? 选题指导, 项目分享:

https://gitee.com/dancheng-senior/project-sharing-1/blob/master/%E6%AF%95%E8%AE%BE%E6%8C%87%E5%AF%BC/README.md

1 简介

基于Arduino制作的一个计算器。使用4X4键盘和Arduino Uno制作。该计算器将能够执行简单的数学运算,如加法、减法、乘法和除法。它也可以支持带小数点运算。

2 主要器件

  • Arduino UNO开发板
  • 4x4键盘
  • 16x2 I2C LCD显示器
  • 跳线
  • Arduino IDE

3 实现效果

在这里插入图片描述

4 硬件说明

电路图和说明

4X4键盘有8个引脚需要连接到从D2到D9的Arduino引脚,如下所示:

在这里插入图片描述
然后,按如下方式将LCD与Arduino连接:

在这里插入图片描述

除数字按钮外,其他按钮的作用如下:

  • 'A’用于加法

  • 'B’用于减法

  • 'C’用于清零

  • 'D’用于除法

  • '*'用于乘法

完整的电路图如下

在这里插入图片描述

5 软件代码说明

以下是项目所需的代码以及每个代码段的作用。

首先,您需要为键盘和I2C LCD显示添加库。使用的LCD显示屏通过I2C通信与UNO配合使用,因此使用允许Arduino上的I2C通信的wire库。然后,按照4X4键盘的引脚连接以及键盘按钮执行操作的说明进行操作。

#include<Keypad.h>
#include<LiquidCrystal_I2C.h>
#include<Wire.h>

const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1', '2', '3', '+'},
  {'4', '5', '6', '-'},
  {'7', '8', '9', 'C'},
  {'*', '0', '=', '/'}
};

byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};

在setup()函数中,显示屏将显示“Arduino calculator”。

lcd.begin();
  lcd.setCursor(0, 0);
  lcd.print("Arduino Calculator");
  delay(1000);
  scrollDisplay();
  clr();

在loop()函数中,我们首先得到按下的键然后我们需要检查按下的键是否是数字键。如果是数字,则它将存储在firstNum字符串中。

char newKey = myKeypad.getKey();
  if (newKey != NO_KEY && (newKey == '1' || newKey == '2' || newKey == '3' || newKey == '4' || newKey == '5' || newKey == '6' || newKey == '7' || newKey == '8' || newKey == '9' || newKey == '0')) {

    if (firstNumState == true) {
      firstNum = firstNum + newKey;

      lcd.print(newKey);
    }
    else {
      secondNum = secondNum + newKey;

      lcd.print(newKey);
    }

如果按下的键不是数字,请检查它是’+‘、’ - ‘、’/‘、’‘(在键盘上,这些键是’A’、‘B’、‘D’、'’ )。如果它来自这些键,我们将存储稍后将使用的值。它还会将firstNum设置为false,这意味着我们现在将得到第二个数字。

现在,其他数值将存储在secondNum字符串中。

if (newKey != NO_KEY && (newKey == '+' || newKey == '-' || newKey == '*' || newKey == '/')) {
    if (firstNumState == true) {
      operatr = newKey;
      firstNumState = false;
      lcd.setCursor(15, 0);
      lcd.print(operatr);
      lcd.setCursor(5, 1);
    }
  }

最后,我们将其设置为如果按下的键不是来自操作键,它将检查它是否为’='。如果是这个键,那么它将对第一个和第二个数字执行存储操作并输出结果。

设置完代码后,计算器将能够执行方程式。文章来源地址https://uudwc.com/A/dOAv

if (newKey != NO_KEY && newKey == '=') {
    if (operatr == '+') {
      result = firstNum.toFloat() + secondNum.toFloat();
    }

    if (operatr == '-') {
      result = firstNum.toFloat() - secondNum.toFloat();
    }

    if (operatr == '*') {
      result = firstNum.toFloat() * secondNum.toFloat();
    }

    if (operatr == '/') {
      result = firstNum.toFloat() / secondNum.toFloat();
    }
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(firstNum);
    lcd.print(operatr);
    lcd.print(secondNum);
    lcd.setCursor(0, 1);
    lcd.print("=");
    lcd.print(result);
    firstNumState = true;
  }


And if the key will be 'C', then it will clear the display screen.
if (newKey != NO_KEY && newKey == 'C') {
    clr();
  }

最后

原文地址:https://blog.csdn.net/m0_71572576/article/details/129314209

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请联系站长进行投诉反馈,一经查实,立即删除!

h
上一篇 2023年06月16日 02:28
MindSpore保姆级安装教程
下一篇 2023年06月16日 02:29