Cov txheej txheem:

Siv Numeric Keypads Nrog Arduino: 4 Kauj Ruam
Siv Numeric Keypads Nrog Arduino: 4 Kauj Ruam

Video: Siv Numeric Keypads Nrog Arduino: 4 Kauj Ruam

Video: Siv Numeric Keypads Nrog Arduino: 4 Kauj Ruam
Video: $600 NYIAJ PAB CA * $3600 CHILD TAX * BIDEN SPEECH * INDIA KAB MOB HNYAV * TOP NEWS+ 04/29/2021 2024, Kaum ib hlis
Anonim
Siv Numeric Keypads Nrog Arduino
Siv Numeric Keypads Nrog Arduino

Cov lej lej tuaj yeem muab cov neeg siv yooj yim kawg rau lwm qhov cuam tshuam rau koj cov phiaj xwm. Lossis yog tias koj xav tau khawm ntau, lawv tuaj yeem txuag koj ntau lub sijhawm nrog rau kev tsim kho. Peb yuav khiav los ntawm kev txuas lawv, siv Arduino lub tsev qiv ntawv thiab tom qab ntawd ua tiav nrog cov qauv piv txwv muaj txiaj ntsig.

Kauj ruam 1: Pib

Pib Pib
Pib Pib

Tsis muaj teeb meem qhov twg koj tau txais koj cov keypads los ntawm, nco ntsoov tias koj tuaj yeem tau txais cov ntaub ntawv - raws li qhov no yuav ua rau lub neej yooj yim dua thaum txuas lawv. Piv txwv li - cov duab hauv cov kauj ruam no.

Cov ntaub ntawv tseem ceeb raws li nws yuav qhia koj tias tus pin lossis cov txuas sib txuas ntawm cov keyboard yog rau kab thiab kab. Yog tias koj tsis muaj cov ntaub ntawv - koj yuav tsum txiav txim siab tus kheej tias cov neeg sib tham yog rau kab thiab kab.

Qhov no tuaj yeem ua tiav siv qhov ua haujlwm txuas ntxiv ntawm multimeter (lub suab nrov). Pib los ntawm kev tso ib qho kev sojntsuam ntawm tus pin 1, lwm qhov kev sojntsuam ntawm tus pin 2, thiab nias tus yuam sij ib tus zuj zus. Sau tseg thaum lub pob ua tiav lub Circuit Court, tom qab ntawd txav mus rau tus pin tom ntej. Tsis ntev koj yuav paub tias yog leej twg. Piv txwv li, ntawm tus piv txwv keypad pins 1 thiab 5 yog rau khawm “1 ″, 2 thiab 5 rau“4 ″, thiab lwm yam…

Txij ntawm no mus thov rub tawm thiab teeb tsa lub keyboard keyboard Arduino. Tam sim no peb yuav ua qauv qhia siv ob lub keypads hauv cov piv txwv yooj yim.

Kauj Ruam 2: Siv 12 Tus lej Keypad

Peb yuav siv cov keyboard me me dub, Arduino Uno-tau tshaj thiab LCD nrog I2C interface rau lub hom phiaj tso saib. Yog tias koj tsis muaj lub LCD koj ib txwm tuaj yeem xa cov ntawv mus rau tus saib xyuas txuas ntxiv.

Hlau koj lub LCD ces txuas cov keyboard mus rau Arduino raws li hauv qab no: Keypad row 1 to Arduino digital 5Keypad row 2 to Arduino digital 4Keypad row 3 to Arduino digital 3Keypad row 4 to Arduino digital 2Keypad column 1 to Arduino digital 8Keypad column 2 to Arduino digital 7Keypad kem 3 rau Arduino digital 6 Yog tias koj cov keyboard sib txawv rau peb, nco ntsoov cov kab hauv kab kos los ntawm:

// keypad hom txhais

Raws li koj xav tau hloov tus lej hauv kab ntawv rowPins [ROWS] thiab colPins [COLS]. Koj nkag mus rau tus lej lej tus lej txuas nrog kab thiab kab ntawm cov keypad feem.

Ib qho ntxiv, cov yuam sij array khaws cov txiaj ntsig tso tawm hauv LCD thaum lub pob tshwj xeeb raug nias. Koj tuaj yeem pom peb tau sib phim nws nrog lub khawm lub cev siv, txawm li cas los xij koj tuaj yeem hloov nws mus rau qhov koj xav tau. Tab sis tam sim no, nkag mus thiab xa cov duab kos hauv qab no thaum koj txaus siab rau kab/tus lej tus lej faib:

/ * Cov lej lej thiab I2C LCD https://tronixstuff.com Siv Lub tsev qiv ntawv Keypad rau Arduino https://www.arduino.cc/playground/Code/Keypad los ntawm Mark Stanley, Alexander Brevig */

#suav nrog "Keypad.h"

#suav nrog "Wire.h" // rau I2C LCD #include "LiquidCrystal_I2C.h" // rau I2C npav LCD module // https://www.dfrobot.com/wiki/index.php/I2C/TWI_LCD1602_Module_(SKU: _DFR0063) LiquidCrystal_I2C lcd (0x27, 16, 2); // teeb tsa qhov chaw nyob LCD rau 0x27 rau 16 tus cim thiab 2 kab lus tso tawm

// keypad hom txhais

const byte ROWS = 4; // plaub kab const byte COLS = 3; // peb kab ntawv char keys [ROWS] [COLS] = {{'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}, {'*', '0', '#'}};

byte rowPins [ROWS] = {

5, 4, 3, 2}; // txuas rau kab pinouts ntawm cov keyboard byte colPins [COLS] = {8, 7, 6}; // txuas mus rau kab ntawv pinouts ntawm cov keyboard

int suav = 0;

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

void teeb tsa ()

{lcd.init (); // pib lub lcd lcd.backlight (); // qhib lub teeb nraub qaum LCD}

void lub voj ()

{char qhov tseem ceeb = keypad.getKey (); yog (qhov tseem ceeb! = NO_KEY) {lcd.print (qhov tseem ceeb); suav ++; yog (suav == 17) {lcd.clear (); suav = 0; }}}

Thiab cov txiaj ntsig ntawm qhov kos duab tau qhia hauv video. Yog li tam sim no koj tuaj yeem pom yuav ua li cas lub pob nyem tuaj yeem txhais ua cov ntaub ntawv siv rau hauv daim duab. Tam sim no peb yuav rov ua qhov kev ua qauv qhia no nrog cov keyboard loj dua.

Kauj Ruam 3: Siv Tus lej 16 Tus lej

Peb yuav siv tus lej loj 4 × 4, Arduino Uno-tau tshaj thiab rau kev hloov pauv I2C LCD los ntawm Akafugu rau lub hom phiaj tso saib. Ib zaug ntxiv, yog tias koj tsis muaj lub LCD koj tuaj yeem xa cov ntawv mus rau tus saib xyuas txuas ntxiv. Hlau txuas lub LCD thiab tom qab ntawd txuas lub keyboard mus rau Arduino raws li hauv qab no:

  • Keypad kab 1 (tus pin yim) rau Arduino digital 5
  • Keypad kab 2 (tus pin 1) rau Arduino digital 4
  • Keypad kab 3 (tus pin 2) rau Arduino digital 3
  • Keypad kab 4 (tus pin 4) rau Arduino digital 2
  • Keypad kem 1 (tus pin 3) rau Arduino digital 9
  • Keypad kem 2 (tus pin 5) rau Arduino digital 8
  • Keypad kem 3 (tus pin 6) rau Arduino digital 7
  • Keypad kem 4 (tus pin 7) rau Arduino digital 6

Tam sim no rau qhov kos duab - nco tseg tias peb tau haum rau cov lej loj tus lej: kab ntawv ntxiv hauv kab ntawv siv tus lej tus pin ntxiv hauv kab array colPins thiab byte COLS = 4.

/ * Cov lej lej thiab I2C LCD https://tronixstuff.com Siv Lub tsev qiv ntawv Keypad rau Arduino https://www.arduino.cc/playground/Code/Keypad los ntawm Mark Stanley, Alexander Brevig */

#suav nrog "Keypad.h"

#suav nrog "Wire.h" // rau I2C LCD #include "TWILiquidCrystal.h" // https://store.akafugu.jp/products/26 LiquidCrystal lcd (12, 11, 5, 4, 3, 2);

const byte ROWS = 4; // plaub kab

const byte COLS = 4; // plaub kab char char [ROWS] [COLS] = {{'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'}}; byte rowPins [ROWS] = {5, 4, 3, 2}; // txuas rau kab pinouts ntawm cov keyboard byte colPins [COLS] = {9, 8, 7, 6}; // txuas mus rau kab ntawv pinouts ntawm cov keypad int suav = 0;

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

void teeb tsa ()

{Serial.begin (9600); lcd.begin (16, 2); lcd.print ("Ntsuas ntsuas!"); ncua (1000); lcd.clear (); }

void lub voj ()

{char qhov tseem ceeb = keypad.getKey (); yog (qhov tseem ceeb! = NO_KEY) {lcd.print (qhov tseem ceeb); Serial.print (qhov tseem ceeb); suav ++; yog (suav == 17) {lcd.clear (); suav = 0; }}}

Thiab dua koj tuaj yeem pom cov txiaj ntsig ntawm qhov kos duab saum toj no hauv video.

Tam sim no rau qhov piv txwv txoj haujlwm, ib qho uas tej zaum yuav tau siv ntau tshaj ntawm cov lej lej…

Kauj Ruam 4: Piv Txwv Txoj Haujlwm - Tus Txheej Txheem PIN

Kev thov feem ntau siv rau tus lej lej zoo li yog "PIN" daim ntawv thov, qhov uas Arduino tau qhia kom ua qee yam raws tus lej raug raug nkag mus rau hauv cov keyboard. Cov duab kos hauv qab no siv kho vajtse piav qhia rau yav dhau los kos duab thiab siv tus lej rau tus lej PIN nkag mus.

Qhov kev nqis tes ua tuaj yeem tso rau hauv kev ua haujlwm raug cai PIN () thiab tsis raug PIN (). Thiab tus lej PIN tau teeb tsa hauv kab ntawv tus lej PIN [6]. Nrog kev ua haujlwm ntxiv me ntsis koj tuaj yeem tsim koj tus kheej tus lej PIN-hloov ua haujlwm ib yam.

// PIN hloov nrog 16 tus lej tus lej lej // https://tronixstuff.com #include "Keypad.h" #include #include LiquidCrystal lcd (12, 11, 5, 4, 3, 2);

const byte ROWS = 4; // plaub kab

const byte COLS = 4; // plaub kab char char [ROWS] [COLS] = {{'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'}}; byte rowPins [ROWS] = {5, 4, 3, 2}; // txuas rau kab pinouts ntawm cov keyboard byte colPins [COLS] = {9, 8, 7, 6}; // txuas mus rau kab ntawv pinouts ntawm cov keyboard

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

tus PIN [6] = {

'1', '2', 'A', 'D', '5', '6'}; // peb zais (!) tus lej char sim [6] = {'0', '0', '0', '0', '0', '0'}; // siv rau kev sib piv int z = 0;

void teeb tsa ()

{Serial.begin (9600); lcd.begin (16, 2); lcd.print ("PIN Xauv"); ncua (1000); lcd.clear (); lcd.print ("Sau tus lej PIN …"); }

void correctPIN () // ua qhov no yog nkag tus lej PIN raug

{lcd.print (" * PIN raug *"); ncua (1000); lcd.clear (); lcd.print ("Sau tus lej PIN …"); }

void incorrectPIN () // ua qhov no yog tus lej PIN tsis raug nkag mus

{lcd.print (" * Sim dua *"); ncua (1000); lcd.clear (); lcd.print ("Sau tus lej PIN …"); }

void checkPIN ()

{int raug = 0; koj i; rau (kuv = 0; kuv <6; kuv ++) {

yog (sim [kuv] == PIN [kuv])

{tseeb ++; }} yog (raug == 6) {correctPIN (); } lwm {incorrectPIN (); }

rau (int zz = 0; zz <6; zz ++) {sim [zz] = '0'; }}

tsis muaj dab tsi readKeypad ()

{char qhov tseem ceeb = keypad.getKey (); yog (qhov tseem ceeb! = NO_KEY) {sim [z] = qhov tseem ceeb; z ++; hloov (qhov tseem ceeb) {rooj plaub '*': z = 0; tawg; cov ntaub ntawv '#': z = 0; ncua (100); // rau kev nthuav tawm ntxiv lcd.clear (); checkPIN (); tawg; }}}

void lub voj ()

{readKeypad (); }

Peb tes num tau qhia hauv daim vis dis aus.

Yog li tam sim no koj muaj peev xwm siv kaum ob thiab kaum rau-khawm-khawm nrog koj li Arduino systems. Kuv paub tseeb tias koj yuav los nrog qee yam muaj txiaj ntsig thiab ntxim nyiam siv cov keypads yav tom ntej.

Cov ntawv tshaj tawm no tau coj tuaj rau koj los ntawm pmdway.com - txhua yam rau cov kws tsim khoom thiab cov khoom siv hluav taws xob, nrog kev xa khoom dawb thoob ntiaj teb.

Pom zoo: