Cov txheej txheem:

Arduino Calculator Siv 4X4 Keypad: 4 Cov Kauj Ruam (nrog Duab)
Arduino Calculator Siv 4X4 Keypad: 4 Cov Kauj Ruam (nrog Duab)

Video: Arduino Calculator Siv 4X4 Keypad: 4 Cov Kauj Ruam (nrog Duab)

Video: Arduino Calculator Siv 4X4 Keypad: 4 Cov Kauj Ruam (nrog Duab)
Video: And You, How Would You Lift A BMW R 1250 GS? Criminel Rider #shorts #bmw 2024, Kaum ib hlis
Anonim
Image
Image

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. 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 ua haujlwm zoo nrog Arduino qhov ua haujlwm.

Khoom siv

Arduino Ib

16 × 2 LCD Zaub

4 × 4 Keypad

Cov qhob cij

Jumper Cables

Arduino Kab

Kauj ruam 1: Schematics

Kauj Ruam 2: Txhim Kho Tsev Qiv Ntawv:

Raws li tau hais ua ntej peb tab tom cuam tshuam lub 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. Rau Keypad lub tsev qiv ntawv (nyem rau ntawm qhov txuas mus 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 lub cajmeem.

Kauj ruam 3: Source Code:

/*

© Techtronic Harsh

*/

#suav nrog

#suav nrog

LiquidCrystal lcd (0, 1, 2, 3, 4, 5);

const byte ROWS = 4; const byte COLS = 4;

tus yuam sij [ROWS] [COLS] = {

{'1', '2', '3', '+'}, {'4', '5', '6', '-'}, {'7', '8', '9', ' *'}, {' C ',' 0 ',' = ','/'}}; byte rowPins [ROWS] = {13, 12, 11, 10}; byte colPins [COLS] = {9, 8, 7, 6};

Keypad myKeypad = Keypad (uaKeymap (tuav), rowPins, colPins, ROWS, COLS);

boolean presentValue = tsis tseeb;

boolean tom ntej = tsis tseeb; boolean kawg = cuav; String num 1, num2; koj teb; char kev;

void teeb tsa ()

{lcd.begin (16, 2); lcd.setCursor (0, 0); lcd.print ("Techtronic Harsh"); lcd.setCursor (0, 1); lcd.print ("Tshuab xam zauv"); ncua (3000); lcd.clear (); lcd.setCursor (0, 0); lcd.print ("Zoo Li Thiab"); lcd.setCursor (0, 1); lcd.print ("Sau Npe Peb"); ncua (3000); lcd.clear (); }

void voj () {

char tseem ceeb = myKeypad.getKey ();

if (key! = NO_KEY && (key == '1' || key == '2' || key == '3' || key == '4' || key == '5' || key = = '6' || qhov tseem ceeb == '7' || qhov tseem ceeb == '8' || qhov tseem ceeb == '9' || qhov tseem ceeb == '0'))

{yog (presentValue! = tseeb) {num1 = num1 + qhov tseem ceeb; int numLength = num1.length (); lcd.setCursor (15 - numLength, 0); // txhawm rau kho ib qho chaw dawb rau tus neeg siv lcd.print (num1); } lwm {num2 = num2 + qhov tseem ceeb; int numLength = num2.length (); lcd.setCursor (15 - numLength, 1); lcd.print (num2); kawg = muaj tseeb; }}

lwm tus yog (presentValue == tsis tseeb && qhov tseem ceeb! = NO_KEY && (qhov tseem ceeb == '/' || qhov tseem ceeb == '*' || qhov tseem ceeb == '-' || qhov tseem ceeb == '+'))

{yog (presentValue == tsis tseeb) {presentValue = muaj tseeb; op = qhov tseem ceeb; lcd.setCursor (15, 0); lcd.print (op); }}

lwm tus yog (qhov kawg == tseeb && qhov tseem ceeb! = NO_KEY && qhov tseem ceeb == '=') {

yog (op == ' +') {teb = num1.toInt () + num2.toInt (); } lwm tus yog (op == ' -') {teb = num1.toInt () - num2.toInt (); } lwm tus yog (op == ' *') {teb = num1.toInt () * num2.toInt (); } lwm tus yog (op == ' /') {teb = num1.toInt () / num2.toInt (); } lcd.clear (); lcd.setCursor (15, 0); lcd.autoscroll (); lcd.print (teb); lcd.noAutoscroll (); } lwm yog (qhov tseem ceeb! = NO_KEY && qhov tseem ceeb == 'C') {lcd.clear (); presentValue = tsis tseeb; kawg = tsis tseeb; num1 = ""; num2 = ""; teb = 0; ua = ''; }}

/*

© Techtronic Harsh

*/

Kauj ruam 4: Ua haujlwm:

Ua cov kev sib txuas raws li daim duab qhia chaw thiab xa cov cai. 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.

Cim ntawm Keypad thiab Assumption:

  • "A" - Ntxiv (+)
  • "B" - Kev rho tawm (-)
  • "C" - Sib npaug (*)
  • "D" - Division (/)
  • "*" - Ntshiab (C)
  • "#" - Sib npaug (=)

Pom zoo: