本教程是的一部分: 键盘
这里列出了所有键盘视频。
How to Use a 5x4 20-Key Keypad with Arduino to Detect Strings
Using a keypad with keys containing more than one character is challenging. I have written code to remove the channel, and you will be able to readily read virtually any length key value in this video.
本教程是……的一部分: 键盘
- 使用4x3键盘与Arduino
- Arduino Code and Video for a Four-Key Keypad
- Arduino Code and Video: 4x4 Matrix Black Keypad
- Build a Simple Electronic Lock with Keypad and LCD Using Arduino
- Controlling an 8-channel relay with a 4x3 keypad
- How to use 4x4 Soft Keypad with Arduino
- Lesson 67: Controlling an 8-Channel Relay with a Keypad Using Arduino
- 1602 LCD Keypad Shield: Basic Code
321-Resources for this code
语言: C++
/*
*
* Original code from keypad.h library: MultiKey.ino (@author Mark Stanley)
* Written and updated by Ahmad Shamshiri (Robojax.com) on May 06, 2020 at 19:37 in Ajax, Ontario, Canada
*
* This code is for a 5x4 keypad with text (more than 1 character);
* The code was written to allow any text for a key.
* The keypad has the following keys:
"F1", "F2", "#", "*",
"1", "2", "3", "UP",
"4", "5", "6", "DOWN",
"7", "8", "9", "ESC",
"LEFT", "0", "RIGHT", "ENT"
* Video code:
*
* Watch the video for details: https://youtu.be/sbQ3D1_x_tg
*
* See the wiring diagram and full explanation of the code: http://robojax.com/L/?id=62
You can get the wiring diagram and full explanation of this code from my Arduino Course at Udemy.com.
Learn Arduino step by step with all libraries, codes, and wiring diagrams all in one place.
Visit my course now: http://robojax.com/L/?id=62
If you found this tutorial helpful, please support me so I can continue creating
content like this. You can become my Patron and have early access to my videos here: http://robojax.com/L/?id=63
or make a donation using PayPal: http://robojax.com/L/?id=64
*
* Code is available at: http://robojax.com/learn/arduino
* This code is provided "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.
* This code has been downloaded from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <Keypad.h>
const byte ROWS = 5; //5 rows
const byte COLS = 4; //4 columns
char* specialKeys[] ={
"F1", "F2", "#", "*",
"1", "2", "3", "UP",
"4", "5", "6", "DOWN",
"7", "8", "9", "ESC",
"LEFT", "0", "RIGHT", "ENT"
};
char specialKeysID[] = {
'A', 'B', '#', '*',
'1', '2', '3', 'C',
'4', '5', '6', 'D',
'7', '8', '9', 'E',
'F', '0', 'G', 'H'
};
char keys[ROWS][COLS] = {
{specialKeysID[0], specialKeysID[1], specialKeysID[2], specialKeysID[3]},
{specialKeysID[4], specialKeysID[5], specialKeysID[6], specialKeysID[7]},
{specialKeysID[8], specialKeysID[9], specialKeysID[10], specialKeysID[11]},
{specialKeysID[12], specialKeysID[13], specialKeysID[14], specialKeysID[15]},
{specialKeysID[16], specialKeysID[17], specialKeysID[18], specialKeysID[19]}
};
byte rowPins[ROWS] = {2,3,4,5,6}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {10,9,8,7}; //connect to the column pinouts of the kpd
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
unsigned long loopCount;
unsigned long startTime;
String msg;
void setup() {
// Robojax 5x4 keypad test
Serial.begin(9600);
Serial.println("Robojax 5x4 keypad");
}
void loop() {
// Robojax 5x4 keypad test
char key = keypad.getKey();
// just print the pressed key
if (key){
Serial.print("Key: ");
Serial.println(getKey(key));
}
if(getKey(key) =="ENTER")
{
Serial.println("ENTER is pressed");
}
//Robojax.com 5x4 keypad detecting string value
} // End loop
/*
* getKey()
* @brief gets the actual key value from single character
* @param k is character
* @return returns actual key value
* Written by Ahmad Shamshiri for robojax.com
* on May 06, 2020 at 19:37 in Ajax, Ontario, Canada
*/
char* getKey(char k)
{
//Robojax.com 5x4 keypad detecting string value
for(int i=0; i<20; i++)
{
if(specialKeysID[i] ==k) return specialKeys[i];
}
}//getKey
文件📁
没有可用的文件。