哈哈哈哈哈操欧洲电影,久草网在线,亚洲久久熟女熟妇视频,麻豆精品色,久久福利在线视频,日韩中文字幕的,淫乱毛视频一区,亚洲成人一二三,中文人妻日韩精品电影

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

怎樣用4X4鍵盤和ArduinoUno制作Arduino計(jì)算器

454398 ? 來(lái)源:工程師吳畏 ? 2019-08-05 09:51 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

電路圖和說(shuō)明

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

怎樣用4X4鍵盤和ArduinoUno制作Arduino計(jì)算器

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

除了數(shù)字按鈕之外的按鈕將執(zhí)行以下任務(wù):

‘A’用于添加

‘B’用于減法

‘C’用于清除

‘D’用于劃分

‘*’用于乘法

完整的電路圖如下所示。

Arduino計(jì)算器圖。

代碼細(xì)分和演練

我們來(lái)看看查看該項(xiàng)目所需的代碼以及每個(gè)代碼段的作用。

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

然后,按照4X4鍵盤的引腳連接和鍵盤的說(shuō)明進(jìn)行操作按鈕執(zhí)行操作。

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

在設(shè)置功能中,顯示屏將顯示“MakerPro的Arduino計(jì)算器”。

lcd.begin();

lcd.setCursor(0, 0);

lcd.print(“Arduino Calculator”);

lcd.setCursor(0, 1);

lcd.print(“by MakerPro”);

delay(1000);

scrollDisplay();

clr();

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

}

如果按下的鍵不是數(shù)字,請(qǐng)檢查是否為‘+’,‘ - ’,‘/’,‘*’(在thekeypad上,這些鍵是‘A’,‘B’,‘D’,‘*’)。如果它來(lái)自這些鍵,我們將存儲(chǔ)稍后將使用的值。它還會(huì)將firstNum設(shè)置為false,這意味著我們現(xiàn)在將得到第二個(gè)數(shù)字。

現(xiàn)在,其他數(shù)值將存儲(chǔ)在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);

}

}

最后,我們?cè)O(shè)置它,所以如果按下的鍵不是來(lái)自操作鍵,它將檢查它是否是‘=’。如果是這個(gè)鍵,那么它將對(duì)第一個(gè)和第二個(gè)數(shù)字執(zhí)行存儲(chǔ)操作并輸出結(jié)果。

設(shè)置完代碼后,計(jì)算器將能夠執(zhí)行方程式。

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

}

完整計(jì)算器項(xiàng)目代碼

#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 = ‘ ’;

}

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 計(jì)算器
    +關(guān)注

    關(guān)注

    16

    文章

    441

    瀏覽量

    38995
  • Arduino
    +關(guān)注

    關(guān)注

    190

    文章

    6527

    瀏覽量

    197408
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評(píng)論

    相關(guān)推薦
    熱點(diǎn)推薦

    TMS570LS31x4/21x4微控制:高安全標(biāo)準(zhǔn)下的強(qiáng)大之選

    TMS570LS31x4/21x4微控制:高安全標(biāo)準(zhǔn)下的強(qiáng)大之選 在電子設(shè)計(jì)領(lǐng)域,對(duì)于高性能且適用于安全關(guān)鍵應(yīng)用的微控制的需求與日俱增。德州儀器(TI)的TMS570LS31
    的頭像 發(fā)表于 02-09 17:10 ?492次閱讀

    探索DS90CP04:1.5 Gbps 4x4 LVDS交叉點(diǎn)開關(guān)的卓越性能

    探索DS90CP04:1.5 Gbps 4x4 LVDS 交叉點(diǎn)開關(guān)的卓越性能 在當(dāng)今高速數(shù)據(jù)傳輸?shù)臅r(shí)代,低抖動(dòng)、低偏斜的高速開關(guān)設(shè)備對(duì)于確保數(shù)據(jù)的高效、準(zhǔn)確傳輸至關(guān)重要。DS90CP04作為一款由
    的頭像 發(fā)表于 12-30 14:50 ?508次閱讀

    解析SN65LVDS125A和SN65LVDT125A:4x4非阻塞交叉點(diǎn)開關(guān)的卓越性能

    解析SN65LVDS125A和SN65LVDT125A:4x4非阻塞交叉點(diǎn)開關(guān)的卓越性能 在電子設(shè)計(jì)領(lǐng)域,高速信號(hào)處理和靈活的信號(hào)路由是許多應(yīng)用的關(guān)鍵需求。德州儀器(TI)的SN65LVDS125A
    的頭像 發(fā)表于 12-29 17:40 ?707次閱讀

    探索SN65LVDS125A和SN65LVDT125A:4x4非阻塞交叉點(diǎn)開關(guān)的卓越性能

    探索SN65LVDS125A和SN65LVDT125A:4x4非阻塞交叉點(diǎn)開關(guān)的卓越性能 在當(dāng)今高速發(fā)展的電子領(lǐng)域,數(shù)據(jù)傳輸和信號(hào)處理的速度和效率至關(guān)重要。而SN65LVDS125A
    的頭像 發(fā)表于 12-29 17:40 ?830次閱讀

    探索SN65LVDS250和SN65LVDT250:高性能LVDS 4x4交叉點(diǎn)開關(guān)

    探索SN65LVDS250和SN65LVDT250:高性能LVDS 4x4交叉點(diǎn)開關(guān) 在高速數(shù)據(jù)傳輸?shù)念I(lǐng)域中,對(duì)于實(shí)現(xiàn)高效、穩(wěn)定的數(shù)據(jù)交換,合適的開關(guān)器件至關(guān)重要。今天咱就來(lái)深入探討一下TI推出
    的頭像 發(fā)表于 12-29 17:10 ?612次閱讀

    深入解析SN65LVDS250與SN65LVDT250:高性能4x4 LVDS交叉點(diǎn)開關(guān)

    深入解析SN65LVDS250與SN65LVDT250:高性能4x4 LVDS交叉點(diǎn)開關(guān) 在高速數(shù)據(jù)處理與傳輸?shù)念I(lǐng)域中,交叉點(diǎn)開關(guān)作為關(guān)鍵組件,對(duì)于數(shù)據(jù)的靈活路由和高效傳輸起著至關(guān)重要的作用。今天
    的頭像 發(fā)表于 12-29 17:10 ?661次閱讀

    探索SN65LVCP404:高性能千兆4x4交叉點(diǎn)開關(guān)的技術(shù)剖析

    探索SN65LVCP404:高性能千兆4x4交叉點(diǎn)開關(guān)的技術(shù)剖析 在高速數(shù)據(jù)傳輸?shù)碾娮宇I(lǐng)域,一款性能卓越的交叉點(diǎn)開關(guān)對(duì)于確保數(shù)據(jù)的高效、穩(wěn)定傳輸至關(guān)重要。今天,我們就來(lái)深入剖析德州儀器(TI
    的頭像 發(fā)表于 12-26 14:25 ?416次閱讀

    深入剖析DS10CP154A:1.5 Gbps 4x4 LVDS交叉點(diǎn)開關(guān)的卓越性能與應(yīng)用

    深入剖析DS10CP154A:1.5 Gbps 4x4 LVDS 交叉點(diǎn)開關(guān)的卓越性能與應(yīng)用 在高速信號(hào)處理和路由領(lǐng)域,德州儀器(TI)的DS10CP154A 1.5 Gbps 4x4 LVDS
    的頭像 發(fā)表于 12-26 11:15 ?501次閱讀

    探索DS25CP104A/DS25CP114 3.125 Gbps 4x4 LVDS交叉點(diǎn)開關(guān)的奧秘

    探索DS25CP104A/DS25CP114 3.125 Gbps 4x4 LVDS交叉點(diǎn)開關(guān)的奧秘 在高速信號(hào)路由和切換的領(lǐng)域里,DS25CP104A和DS25CP114這兩款由德州儀器推出
    的頭像 發(fā)表于 12-24 17:45 ?775次閱讀

    基于VL53L4CX的飛行時(shí)間傳感擴(kuò)展板:X-NUCLEO-53L4A2技術(shù)解析

    STMicroelectronics X-NUCLEO-53L4A2擴(kuò)展板設(shè)計(jì)用于配備Arduino R3連接的任何STM32 Nucleo開發(fā)板。X-NUCLEO-53L4A2擴(kuò)展
    的頭像 發(fā)表于 10-30 16:10 ?970次閱讀
    基于VL53L<b class='flag-5'>4</b>CX的飛行時(shí)間傳感<b class='flag-5'>器</b>擴(kuò)展板:<b class='flag-5'>X-NUCLEO-53L4</b>A2技術(shù)解析

    Qorvo全新設(shè)計(jì)計(jì)算器:晶振選型、能耗預(yù)算計(jì)算器和鏈路預(yù)算與覆蓋范圍計(jì)算器

    款功能強(qiáng)大的PC端計(jì)算工具 。這些工具—— 晶振采購(gòu)工具 、 能耗預(yù)算計(jì)算器 和 鏈路預(yù)算與覆蓋范圍計(jì)算器 ——讓優(yōu)化晶振選型、預(yù)測(cè)電池續(xù)航時(shí)間以及評(píng)估RF鏈路性能變得前所未有地簡(jiǎn)單。 接下來(lái),讓我們深入了解每一款
    的頭像 發(fā)表于 06-24 17:51 ?1823次閱讀
    Qorvo全新設(shè)計(jì)<b class='flag-5'>計(jì)算器</b>:晶振選型、能耗預(yù)算<b class='flag-5'>計(jì)算器</b>和鏈路預(yù)算與覆蓋范圍<b class='flag-5'>計(jì)算器</b>

    VirtualLab:衍射角計(jì)算器

    介質(zhì)的折射率、結(jié)構(gòu)的周期和入射角。這種相關(guān)性在數(shù)學(xué)上被編碼在光柵方程中。在這個(gè)例中,我們介紹了VirtualLab Fusion的衍射角計(jì)算器,這是一個(gè)用于計(jì)算光柵方程的方便工具。 打開衍射角
    發(fā)表于 06-16 08:48

    HMC629ALP4E 3dB LSB GaAs MMIC 4位數(shù)字衰減,DC-10GHz技術(shù)手冊(cè)

    /TTL,可接受三線式串行輸入或4位并行字。HMC629ALP4E采用符合RoHS標(biāo)準(zhǔn)的4x4 mm QFN無(wú)鉛封裝,無(wú)需外部匹配元件。
    的頭像 發(fā)表于 04-24 09:31 ?1167次閱讀
    HMC629ALP<b class='flag-5'>4</b>E 3dB LSB GaAs MMIC <b class='flag-5'>4</b>位數(shù)字衰減<b class='flag-5'>器</b>,DC-10GHz技術(shù)手冊(cè)

    HMC705LP4/HMC705LP4E 6.5GHz可編程分頻SMT技術(shù)手冊(cè)

    HMC705LP4(E)是一款低噪聲GaAs HBT可編程分頻,采用4x4 mm無(wú)引腳表貼封裝。 該分頻可以通過(guò)編程設(shè)置為以N = 1到N = 17之間的任意數(shù)字進(jìn)行分頻(最高6.
    的頭像 發(fā)表于 04-18 14:14 ?1251次閱讀
    HMC705LP<b class='flag-5'>4</b>/HMC705LP<b class='flag-5'>4</b>E 6.5GHz可編程分頻<b class='flag-5'>器</b>SMT技術(shù)手冊(cè)

    HMC695LP4/HMC695LP4E x4有源倍頻,11.4-13.2GHz輸出技術(shù)手冊(cè)

    HMC695LP4(E)是一款利用InGaP GaAs HBT技術(shù)制造而成的有源微型x4倍頻,采用4x4 mm無(wú)鉛表貼封裝。 在+5V電源電壓下,功率輸出為+7 dBm(典型值)且相
    的頭像 發(fā)表于 04-18 14:07 ?1101次閱讀
    HMC695LP<b class='flag-5'>4</b>/HMC695LP<b class='flag-5'>4</b>E <b class='flag-5'>x4</b>有源倍頻<b class='flag-5'>器</b>,11.4-13.2GHz輸出技術(shù)手冊(cè)
    廊坊市| 南和县| 电白县| 茂名市| 宾川县| 芷江| 安塞县| 荥阳市| 汾阳市| 天等县| 二连浩特市| 定州市| 新野县| 乐东| 郎溪县| 南华县| 宣城市| 岐山县| 图们市| 泗水县| 延安市| 高平市| 福鼎市| 炉霍县| 南投市| 武强县| 木兰县| 巢湖市| 莒南县| 绥滨县| 太和县| 清水河县| 习水县| 深州市| 桂林市| 壤塘县| 丘北县| 凤城市| 长治县| 陈巴尔虎旗| 漳平市|