Cov txheej txheem:

Arduino Calculator: 6 Kauj Ruam
Arduino Calculator: 6 Kauj Ruam

Video: Arduino Calculator: 6 Kauj Ruam

Video: Arduino Calculator: 6 Kauj Ruam
Video: Amazing arduino project 2024, Kaum ib hlis
Anonim
Arduino Tshuab xam zauv
Arduino Tshuab xam zauv

Kev ua haujlwm ib txwm muaj kev lom zem thiab Arduino yog lub platform zoo yog tias koj nyuam qhuav pib nrog Embedded programming. Hauv qhov kev qhia no peb yuav tsim peb tus kheej lub laij lej nrog Arduino. Qhov tseem ceeb tuaj yeem xa mus los ntawm cov keyboard (4 × 4 keypad) thiab cov txiaj ntsig tuaj yeem pom ntawm lub vijtsam LCD (16 × 2 Dot-matrix). Lub tshuab xam zauv no tuaj yeem ua haujlwm yooj yim xws li Ntxiv, Rho Tawm, Muab Zais Tawm thiab faib ua lej. Tab sis thaum koj nkag siab lub tswv yim koj tuaj yeem siv txawm tias muaj txiaj ntsig kev tshawb fawb nrog Arduino qhov kev ua haujlwm. Thaum kawg ntawm txoj haujlwm no koj yuav paub siv 16x2 LCD thiab Keypad nrog Arduino thiab kuj yooj yim npaum li cas nws yog rau kev siv rau lawv siv tau. muaj cov tsev qiv ntawv. Koj tseem yuav nkag siab yuav ua haujlwm li cas rau koj Arduino kom ua tiav txoj haujlwm tshwj xeeb.

Kauj Ruam 1: Yam Yuav Tsum Tau

Arduino Uno (Txhua version yuav ua haujlwm) 16 × 2 LCD Display4 × 4 Keypad9V Roj teebBreadboard thiab txuas xov hlau

Kauj Ruam 2: Daim duab Circuit Court

Daim duab Circuit Court
Daim duab Circuit Court

Kauj Ruam 3: Arduino Calculator Program

Ua tiav qhov program Arduino rau txoj haujlwm no tau muab rau thaum kawg ntawm txoj haujlwm no. Txoj cai tau muab faib ua ntu me me uas muaj txiaj ntsig thiab tau piav qhia hauv qab no. Raws li tau hais ua ntej peb yuav nkag mus rau LCD thiab cov keyboard nrog Arduino siv cov tsev qiv ntawv. Yog li cia peb ntxiv lawv rau peb Arduino IDE ua ntej. Lub tsev qiv ntawv rau LCD twb tau suav nrog hauv koj Arduino los ntawm lub neej ntawd yog li peb tsis tas txhawj txog nws. Txog Keypad tsev qiv ntawv nyem rau ntawm qhov txuas kom rub nws los ntawm Github. Koj yuav tau txais ZIP cov ntaub ntawv, tom qab ntawv ntxiv qhov lib no rau Arduino los ntawm Sketch -> Xws li Lub Tsev Qiv Ntawv -> Ntxiv. ZIP cov ntaub ntawv thiab taw qhia qhov chaw nyob rau cov ntawv rub tawm no. Thaum ua tiav peb txhua tus tau teeb tsa rau kev ua haujlwm. Txawm hais tias peb tau siv lub tsev qiv ntawv rau siv lub keyboard peb yuav tsum hais ob peb yam lus (qhia hauv qab no) txog cov keyboard rau Arduino. Qhov sib txawv ROWS thiab COLS yuav qhia txog pes tsawg kab thiab kab uas peb cov keyboard muaj thiab cov keymap qhia qhov kev txiav txim uas cov yuam sij muaj nyob ntawm cov keyboard. Cov keypad uas kuv tab tom siv hauv txoj haujlwm no zoo li qhov hauv qab no rau daim duab qhia chaw tseem sawv cev ib yam nkaus. Ntxiv mus hauv qab no peb tau hais txog qhov twg pins Cov Keypad txuas nrog siv qhov sib txawv array rowPins thiab colPins.const byte ROWS = 4; // Plaub rowconst byte COLS = 4; // Peb kab ntawv // Txhais cov Keymapchar [ROWS] [COLS] = {{'1', '2', '3', 'A'}, {'4', '5', '6', ' B '}, {' 7 ',' 8 ',' 9 ',' C '}, {'*',' 0 ','#',' D '}}; byte rowPins [ROWS] = {0, 1, 2, 3}; // Txuas cov keyboard ROW0, ROW1, ROW2 thiab ROW3 rau cov Arduino pins.byte colPins [COLS] = {4, 5, 6, 7}; // Txuas cov keyboard COL0, COL1 thiab COL2 rau cov Arduino pins. Thaum peb tau hais txog hom keypad uas peb siv thiab siv nws li cas txuas nrog, peb tuaj yeem tsim cov keypad siv cov ntsiab lus siv kab hauv qab noKeypad kpd = Keypad (uaKeymap (cov yawm sij)), rowPins, colPins, ROWS, COLS); // Tsim Cov Keypad Zoo ib yam peb kuj yuav tsum qhia rau tus pin ntawm Arduino lub LCD txuas nrog. Raws li peb daim duab qhia kab lus cov lus txhais yuav zoo li hauv qab no int rs = 8, en = 9, d4 = 10, d5 = 11, d6 = 12, d7 = 13; // Pins uas LCD txuas nrogLiquidCrystal lcd (rs, en, d4, d5, d6, d7); // tsim lub LCDInside teeb tsa kev ua haujlwm, peb tsuas yog tso saib lub npe ntawm txoj haujlwm thiab tom qab ntawd mus rau thaum lub voj uas qhov haujlwm tseem ceeb nyob. dab tsi raug ntaus thiab tom qab ntawd hloov nws mus rau qhov sib txawv thaum "=" raug nias peb yuav tsum suav qhov tshwm sim thiab tom qab ntawd thaum kawg tso tawm ntawm lub LCD. Qhov no yog qhov ua tiav hauv lub voj ua haujlwm raws li qhia hauv qab no = kpd.getKey (); // khaws cia nias tus nqi tseem ceeb hauv tus lej (tus lej! = NO_KEY) NtesButtons (); yog (qhov tshwm sim == muaj tseeb) CalculateResult (); DisplayResult (); Dab tsi tshwm sim hauv txhua qhov haujlwm tau piav qhia siv kab lus tawm, mus hla cov lej hauv qab no, ntxig ib ncig nrog nws kom nkag siab tias nws ua haujlwm li cas. Yog tias koj muaj kev ua xyem xyav ntawm kab tshwj xeeb, tsis txhob siv cov lus tawm los yog cov rooj sab laj.

Kauj ruam 4:

Kauj Ruam 5: Ua haujlwm ntawm Arduino Calculator

Ua haujlwm ntawm Arduino Calculator
Ua haujlwm ntawm Arduino Calculator

Ua cov kev sib txuas raws li daim duab qhia chaw thiab xa cov cai hauv qab no. Yog tias nws qhia qhov ua yuam kev kom ntseeg tau tias koj tau ntxiv lub tsev qiv ntawv raws li cov lus qhia tau hais los saum no. Koj tseem tuaj yeem sim qhov simulation txhawm rau txheeb xyuas yog tias qhov teeb meem nrog koj lub khoos phis tawj. Yog tias txhua yam ua tiav raws li nws yuav tsum tau ua, tom qab ntawd koj lub khoos phis tawj yuav zoo ib yam li qhov hauv qab no nrog LCD tso tawm qhov noArduino Tshuab xam zauv siv 4x4 Keypad hauv kev nqis tes Vim tias cov keyboard siv ntawm no tsis muaj cov cim raug rau nws Kuv tau xav tias cov ntawv yuav yog tus tswv teev hauv qab no Tus Qauv ntawm KeypadSumed los ua "A" Ntxiv (+) "B" Rho Tawm (-) "C" Sib Cais (*) "D" Division (/) "*" Clear (C) "#" Sib npaug (=) Koj tuaj yeem ua tau siv tus cim kos los sau dab tsi txhua lub pob tau ua piv txwv nrog qhov ua tiav, koj tuaj yeem ncaj qha pib siv lub laij lej. Ntaus tus lej thiab yuav tshwm ntawm kab thib ob nias lub cim ua haujlwm thiab ntaus koj tus lej thib ob thaum kawg nias tus "#" kom tau txais koj qhov txiaj ntsig. Koj tseem tuaj yeem sim tsim lub Touchscreen no raws li Arduino lub laij lej.

Kauj ruam 6: Code

/ * * Arduino Keypad calculator Program */#include // Header file for LCD from https://www.arduino.cc/en/Reference/LiquidCrystal#include // Header file for Keypad from https://github.com/ Chris-A/Keypadconst byte ROWS = 4; // Plaub rowconst byte COLS = 4; // Peb kab ntawv // Txhais cov Keymapchar [ROWS] [COLS] = {{'7', '8', '9', 'D'}, {'4', '5', '6', ' C '}, {' 1 ',' 2 ',' 3 ',' B '}, {'*',' 0 ','#',' A '}}; byte rowPins [ROWS] = {0, 1, 2, 3}; // Txuas cov keyboard ROW0, ROW1, ROW2 thiab ROW3 rau cov Arduino pins.byte colPins [COLS] = {4, 5, 6, 7}; // Txuas keypad COL0, COL1 thiab COL2 rau cov Arduino pins. Keypad kpd = Keypad (uaKeymap (yuam sij), rowPins, colPins, ROWS, COLS); // Tsim Keypadconst int rs = 8, en = 9, d4 = 10, d5 = 11, d6 = 12, d7 = 13; // Pins uas LCD txuas nrogLiquidCrystal lcd (rs, en, d4, d5, d6, d7); ntev Num1, Num2, Number; char qhov tseem ceeb, nqis tes ua; boolean result = cuav; teeb tsa tsis muaj dabtsis () {lcd.begin (16, 2); // Peb tab tom siv 16*2 LCD zaub lcd.print ("DIY Calculator"); // Zaub cov lus qhia lcd.setCursor (0, 1); // teeb tus cursor rau kab 0, kab 1 lcd.print ("-CircuitDigest"); // Tso tawm cov lus qhia qeeb (2000); // Tos rau cov zaub los qhia cov ntaub ntawv lcd.clear (); // Tom qab ntawd ntxuav nws} void loop () {key = kpd.getKey (); // khaws cia nias tus nqi tseem ceeb hauv tus lej (tus lej! = NO_KEY) NtesButtons (); yog (qhov tshwm sim == muaj tseeb) CalculateResult (); DisplayResult (); } void DetectButtons () {lcd.clear (); // Tom qab ntawd ntxuav nws yog (qhov tseem ceeb == '*') // Yog hais tias rho tawm khawm yog nias {Serial.println ("Khawm Nres"); Number = Num1 = Num2 = 0; tshwm sim = tsis tseeb;} yog (qhov tseem ceeb == '1') // Yog tias khawm 1 raug nias {Serial.println ("Khawm 1"); yog (Tus lej == 0) Tus lej = 1; lwm tus lej = (Tus lej*10) + 1; // Nias ob zaug} yog (qhov tseem ceeb == '4') // Yog tias khawm 4 raug nias {Serial.println ("Khawm 4"); yog (Tus lej == 0) Tus lej = 4; lwm tus lej = (Tus lej*10) + 4; // Nias ob zaug} yog (qhov tseem ceeb == '7') // Yog tias khawm 7 raug nias {Serial.println ("Khawm 7"); yog (Tus lej == 0) Tus lej = 7; lwm tus lej = (Tus lej*10) + 7; // Nias ob zaug} yog (qhov tseem ceeb == '0') {Serial.println ("Khawm 0"); // Khawm 0 yog Nias yog (Tus lej == 0) Tus lej = 0; lwm tus lej = (Tus lej*10) + 0; // Nias ob zaug} yog (qhov tseem ceeb == '2') // Nias 2 yog Nias {Serial.println ("Khawm 2"); yog (Tus lej == 0) Tus lej = 2; lwm tus lej = (Tus lej*10) + 2; // Nias ob zaug} yog (qhov tseem ceeb == '5') {Serial.println ("Khawm 5"); yog (Tus lej == 0) Tus lej = 5; lwm tus lej = (Tus lej*10) + 5; // Nias ob zaug} yog (qhov tseem ceeb == '8') {Serial.println ("Khawm 8"); yog (Tus lej == 0) Tus lej = 8; lwm tus lej = (Tus lej*10) + 8; // Nias ob zaug} yog (qhov tseem ceeb == '#') {Serial.println ("Button Equal"); Num2 = Tus lej; result = tseeb; } yog (qhov tseem ceeb == '3') {Serial.println ("Khawm 3"); yog (Tus lej == 0) Tus lej = 3; lwm tus lej = (Tus lej*10) + 3; // Nias ob zaug} yog (qhov tseem ceeb == '6') {Serial.println ("Khawm 6"); yog (Tus lej == 0) Tus lej = 6; lwm tus lej = (Tus lej*10) + 6; // Nias ob zaug} yog (qhov tseem ceeb == '9') {Serial.println ("Khawm 9"); yog (Tus lej == 0) Tus lej = 9; lwm tus lej = (Tus lej*10) + 9; // Nias ob zaug} yog (qhov tseem ceeb == 'A' || qhov tseem ceeb == 'B' || qhov tseem ceeb == 'C' || qhov tseem ceeb == 'D') // Txheeb xyuas Cov Khawm ntawm Kab 4 {Num1 = Tus lej; Zauv = 0; yog (qhov tseem ceeb == 'A') {Serial.println ("Ntxiv"); kev ua = '+';} yog (qhov tseem ceeb == 'B') {Serial.println ("Kev rho tawm"); kev ua = '-'; } yog (qhov tseem ceeb == 'C') {Serial.println ("Multiplication"); kev ua = '*';} yog (qhov tseem ceeb == 'D') {Serial.println ("Devesion"); kev ua = '/';} ncua (100); }} void CalculateResult () {if (action == '+') Number = Num1+Num2; if (action == '-') Number = Num1-Num2; if (action == '*') Number = Num1*Num2; if (action == '/') Number = Num1/Num2; } void DisplayResult () {lcd.setCursor (0, 0); // teeb tus cursor rau kab 0, kab 1 lcd.print (Num1); lcd.print (nqis tes ua); lcd.print (Num2); yog (qhov tshwm sim == muaj tseeb) {lcd.print ("="); lcd.print (Tus lej);} // Tso saib qhov tshwm sim lcd.setCursor (0, 1); // teeb tus cursor rau kab 0, kab 1 lcd.print (Tus lej); // Tso saib qhov tshwm sim}

Pom zoo: