女人自慰AV免费观看内涵网,日韩国产剧情在线观看网址,神马电影网特片网,最新一级电影欧美,在线观看亚洲欧美日韩,黄色视频在线播放免费观看,ABO涨奶期羡澄,第一导航fulione,美女主播操b

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

怎樣用4X4鍵盤和ArduinoUno制作Arduino計算器

454398 ? 來源:工程師吳畏 ? 2019-08-05 09:51 ? 次閱讀

電路圖和說明

4X4鍵盤有8個引腳需要連接到從D2到D9的Arduino引腳,如下所示:

怎樣用4X4鍵盤和ArduinoUno制作Arduino計算器

然后,將LCD連接到Arduino,如下所示:

除了數字按鈕之外的按鈕將執行以下任務:

‘A’用于添加

‘B’用于減法

‘C’用于清除

‘D’用于劃分

‘*’用于乘法

完整的電路圖如下所示。

Arduino計算器圖。

代碼細分和演練

我們來看看查看該項目所需的代碼以及每個代碼段的作用。

首先,您需要為鍵盤和I2C LCD顯示添加庫。使用的LCD顯示器通過I2C通信與UNO配合使用,因此使用允許在Arduino上進行I2C通信的線程庫。

然后,按照4X4鍵盤的引腳連接和鍵盤的說明進行操作按鈕執行操作。

#include

#include

#include

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};

在設置功能中,顯示屏將顯示“MakerPro的Arduino計算器”。

lcd.begin();

lcd.setCursor(0, 0);

lcd.print(“Arduino Calculator”);

lcd.setCursor(0, 1);

lcd.print(“by MakerPro”);

delay(1000);

scrollDisplay();

clr();

在循環功能中,我們先來得到按下的鍵然后我們需要檢查按下的鍵是否是數字鍵。如果是數字,則它將存儲在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);

}

如果按下的鍵不是數字,請檢查是否為‘+’,‘ - ’,‘/’,‘*’(在thekeypad上,這些鍵是‘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);

}

}

最后,我們設置它,所以如果按下的鍵不是來自操作鍵,它將檢查它是否是‘=’。如果是這個鍵,那么它將對第一個和第二個數字執行存儲操作并輸出結果。

設置完代碼后,計算器將能夠執行方程式。

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();

}

完整計算器項目代碼

#include

#include

#include

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};

// Created instances

Keypad myKeypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

LiquidCrystal_I2C lcd(0x27, 16, 2);

boolean firstNumState = true;

String firstNum = “”;

String secondNum = “”;

float result = 0.0;

char operatr = ‘ ’;

void setup() {

lcd.begin();

lcd.setCursor(0, 0);

lcd.print(“Arduino Calculator”);

lcd.setCursor(0, 1);

lcd.print(“by MakerPro”);

delay(1000);

scrollDisplay();

clr();

}

void loop() {

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);

}

}

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);

}

}

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;

}

if (newKey != NO_KEY && newKey == ‘C’) {

clr();

}

}

void scrollDisplay() {

// scroll 13 positions (string length) to the left

// to move it offscreen left:

for (int positionCounter = 0; positionCounter 《 3; positionCounter++) {

// scroll one position left:

lcd.scrollDisplayLeft();

// wait a bit:

delay(300);

}

delay(1000);

// scroll 29 positions (string length + display length) to the right

// to move it offscreen right:

for (int positionCounter = 0; positionCounter 《 3; positionCounter++) {

// scroll one position right:

lcd.scrollDisplayRight();

// wait a bit:

delay(300);

}

delay(2000);

}

void clr() {

lcd.clear();

lcd.setCursor(0, 0);

lcd.print(“1st: ”);

lcd.setCursor(12, 0);

lcd.print(“op ”);

lcd.setCursor(0, 1);

lcd.print(“2nd: ”);

lcd.setCursor(5, 0);

firstNum = “”;

secondNum = “”;

result = 0;

operatr = ‘ ’;

}

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • 計算器
    +關注

    關注

    16

    文章

    439

    瀏覽量

    37917
  • Arduino
    +關注

    關注

    188

    文章

    6490

    瀏覽量

    190065
收藏 人收藏

    評論

    相關推薦
    熱點推薦

    HMC444LP4/444LP4E有源x8倍頻,采用SMT封裝技術手冊

    HMC444LP4(E)是一款有源微型x8倍頻,使用InGaP GaAs HBT技術,采用4x4 mm無引腳表面貼裝封裝。 功率輸出為+6 dBm(典型值),電源電壓為5V,在不同的
    的頭像 發表于 04-17 17:03 ?277次閱讀
    HMC444LP<b class='flag-5'>4</b>/444LP<b class='flag-5'>4</b>E有源<b class='flag-5'>x</b>8倍頻<b class='flag-5'>器</b>,采用SMT封裝技術手冊

    HMC370LP4/370LP4E x4有源倍頻SMT技術手冊

    HMC370LP4(E)是一款利用InGaP GaAs HBT技術制造而成的有源微型x4倍頻,采用4x4 mm無鉛表面貼裝封裝。 在5V電源電壓下,功率輸出為0 dBm(典型值)且相
    的頭像 發表于 04-17 11:30 ?199次閱讀
    HMC370LP<b class='flag-5'>4</b>/370LP<b class='flag-5'>4</b>E <b class='flag-5'>x4</b>有源倍頻<b class='flag-5'>器</b>SMT技術手冊

    HMC368LP4/368LP4E x2有源倍頻SMT技術手冊

    HMC368LP4(E)是一款利用GaAs PHEMT技術制造而成的微型放大器倍頻,采用4x4 mm無鉛表面貼裝封裝。 由+2 dBm信號驅動時,該倍頻在9至16 GHz范圍內提供
    的頭像 發表于 04-17 11:15 ?234次閱讀
    HMC368LP<b class='flag-5'>4</b>/368LP<b class='flag-5'>4</b>E <b class='flag-5'>x</b>2有源倍頻<b class='flag-5'>器</b>SMT技術手冊

    Sky5? LB/LMB/MB/HB 和 4x4 MIMO 分集接收模塊 skyworksinc

    電子發燒友網為你提供()Sky5? LB/LMB/MB/HB 和 4x4 MIMO 分集接收模塊相關產品參數、數據手冊,更有Sky5? LB/LMB/MB/HB 和 4x4 MIMO 分集接收模塊
    發表于 04-11 15:21
    Sky5? LB/LMB/MB/HB 和 <b class='flag-5'>4x4</b> MIMO 分集接收模塊 skyworksinc

    HMC596 CMOS 4x2開關矩陣,采用SMT封裝技術手冊

    HMC596LP4(E)是一款低成本4x2開關矩陣產品,采用無引腳QFN 4x4 mm表貼封裝,可用于衛星/DBS、LNB和200 MHz至3000 MHz的多路開關。 開關上集成由正電壓控制的
    的頭像 發表于 03-07 16:50 ?437次閱讀
    HMC596 CMOS <b class='flag-5'>4x</b>2開關矩陣,采用SMT封裝技術手冊

    LP光纖模式計算器

    的 Bessel 和用于漸變折射率光纖的 Laguerre。 此例展示了如何使用計算器以及如何配置模式的采樣參數。 配置光纖結構:Step-Index Fiber(階躍折射率光纖) 光纖模式計算器允許定義
    發表于 12-18 13:36

    熱敏電阻系數計算器工具指南-BQ769x2

    電子發燒友網站提供《熱敏電阻系數計算器工具指南-BQ769x2.pdf》資料免費下載
    發表于 11-22 15:47 ?0次下載
    熱敏電阻系數<b class='flag-5'>計算器</b>工具指南-BQ769<b class='flag-5'>x</b>2

    基于FPGA的計算器設計

    本文通過FPGA實現8位十進制數的加、減、乘、除運算,通過矩陣鍵盤輸入數據和運算符,矩陣鍵盤的布局圖如下所示。該計算器可以進行連續運算,當按下等號后,可以直接按數字進行下次運算,或者按運算符,把上次運算結果作為本次運算的第一個操
    的頭像 發表于 10-24 14:28 ?1088次閱讀
    基于FPGA的<b class='flag-5'>計算器</b>設計

    開源項目!基于 Arduino DIY 漂亮的宏機械鍵盤

    。 我利用黑色 PLA 材料,通過 3D 打印技術精心制作鍵盤的外殼及其蓋子。外殼上巧妙設置了一個網格,用于安裝按鍵。內部空間則用于放置 Arduino 主板及連接線。此外,我特意在外殼背面預留了一個孔
    發表于 08-19 17:02

    怎樣用Arduino測試鋰電池容量

    本文詳細介紹了如何用Arduino測量鋰電池的容量。并附有電路圖和Arduino的程序代碼。
    的頭像 發表于 07-30 09:14 ?1493次閱讀
    <b class='flag-5'>怎樣用</b><b class='flag-5'>Arduino</b>測試鋰電池容量

    OC5865X資料(參數計算器&amp;原理圖)

    電子發燒友網站提供《OC5865X資料(參數計算器&原理圖).zip》資料免費下載
    發表于 07-17 12:03 ?0次下載

    SN65LVCP404千兆位4x4交叉點開關數據表

    電子發燒友網站提供《SN65LVCP404千兆位4x4交叉點開關數據表.pdf》資料免費下載
    發表于 07-08 11:12 ?0次下載
    SN65LVCP404千兆位<b class='flag-5'>4x4</b>交叉點開關數據表

    DS25CP104A/CP114 3.125 Gbps 4x4 LVDS交叉點開關數據表

    電子發燒友網站提供《DS25CP104A/CP114 3.125 Gbps 4x4 LVDS交叉點開關數據表.pdf》資料免費下載
    發表于 07-04 09:55 ?0次下載
    DS25CP104A/CP114 3.125 Gbps <b class='flag-5'>4x4</b> LVDS交叉點開關數據表

    DS10CP154A 1.5Gbps 4x4 LVDS交叉點開關數據表

    電子發燒友網站提供《DS10CP154A 1.5Gbps 4x4 LVDS交叉點開關數據表.pdf》資料免費下載
    發表于 07-04 09:24 ?0次下載
    DS10CP154A 1.5Gbps <b class='flag-5'>4x4</b> LVDS交叉點開關數據表

    LVDS 4x4交叉點開關SN65LVDS250數據表

    電子發燒友網站提供《LVDS 4x4交叉點開關SN65LVDS250數據表.pdf》資料免費下載
    發表于 06-26 11:12 ?0次下載
    LVDS <b class='flag-5'>4x4</b>交叉點開關SN65LVDS250數據表