Cov txheej txheem:

Arduino DIY Calculator Siv 1602 LCD thiab 4x4 Keypad: 4 Kauj Ruam
Arduino DIY Calculator Siv 1602 LCD thiab 4x4 Keypad: 4 Kauj Ruam

Video: Arduino DIY Calculator Siv 1602 LCD thiab 4x4 Keypad: 4 Kauj Ruam

Video: Arduino DIY Calculator Siv 1602 LCD thiab 4x4 Keypad: 4 Kauj Ruam
Video: How to make Calculator Arduino project 2024, Kaum ib hlis
Anonim
Arduino DIY Tshuab Luam Ntawv Siv 1602 LCD thiab 4x4 Keypad
Arduino DIY Tshuab Luam Ntawv Siv 1602 LCD thiab 4x4 Keypad

Nyob zoo cov neeg hauv phau ntawv qhia no peb yuav ua lub laij lej siv Arduino uas tuaj yeem ua cov lej yooj yim. Yog li ntawd peb yuav siv cov tswv yim los ntawm 4x4 cov keyboard thiab luam tawm cov ntaub ntawv ntawm 16x2 lcd zaub thiab arduino yuav ua qhov kev suav.

Kauj Ruam 1: Yam Koj Xav Tau

Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau

Rau cov lus qhia no peb yuav xav tau cov khoom hauv qab no: Arduino Uno (Txhua version yuav ua haujlwm)

16 × 2 LCD Zaub

4 × 4 Keypad9V BatteryBreadboard Txuas cov xov hlau

Kauj ruam 2: Kev sib txuas

Kev sib txuas
Kev sib txuas
Kev sib txuas
Kev sib txuas

Daim duab kab lus ua tiav ntawm qhov Arduino Calculator Project tau muab rau saum toj no. Qhov +5V thiab kev sib txuas hauv av tau qhia hauv daim duab qhia chaw tuaj yeem tau txais los ntawm 5V thiab tus pin hauv av ntawm Arduino. Arduino nws tus kheej tuaj yeem siv tau los ntawm koj lub laptop lossis los ntawm DC jack siv 12V adapter lossis 9V roj teeb. Cov Keyboard yuav muaj 8 tus pin uas yuav tsum tau txuas nrog los ntawm tus pin 0 rau tus pin 7 raws li tau hais los saum no. Qee qhov Arduino cov laug cam yuav qhia qhov ua yuam kev thaum rub tawm qhov program yog tias muaj dab tsi txuas nrog tus pin 0 thiab tus pin1, yog li yog tias koj muaj ib qho twg tsuas yog tshem tawm keypad thaum rub tawm qhov program.

Kauj ruam 3: Code

Code
Code

Luam cov cai hauv qab no & upload rau nws koj li arduino:/ * * Arduino Keypad lub laij lej Program */#suav nrog "LiquidCrystal.h" // Header file for LCD from https://www.arduino.cc/en/Reference/LiquidCrystal# suav nrog "Keypad.h" // Header file for Keypad los ntawm 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 ncua (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}

Kauj Ruam 4: Lub Tshuab Ntsuas Tawm

Tshuab Zis Tso Tawm
Tshuab Zis Tso Tawm
Tshuab Zis Tso Tawm
Tshuab Zis Tso Tawm
Tshuab Zis Tso Tawm
Tshuab Zis Tso Tawm

Yog li peb ua tiav kev sib txuas & Tshaj tawm cov cai rau arduino thiab nws lub sijhawm los ntsaws lub zog thiab ua qee qhov kev suav suav & raws li koj tuaj yeem pom kuv tab tom suav nrog cov keyboard thiab koj tuaj yeem pom cov txiaj ntsig hauv lcd. Yog li muaj kev lom zem ua koj tus kheej lub tshuab xam zauv diy siv arduino.

Pom zoo: