ขอรบกวนพี่ๆหน่อยครับ จากโปรแกรมด้านล่างเป็นโปรแกรมการรับค่า keypad แบบธรรมดา คือรับได้เพียงหลักเดียว เช่น 1 เมื่อกดอีกครั้ง x ก็จะเปลี่ยน โดยที่เลข1ก่อนหน้าโดนลบไป ถ้าหากผมอยากให้ keypadส่งค่า มาสองหลัก เช่น 20 มีวิธีการเขียนยังไงครับ ขอบคุณครับ
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] =
{
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'#','0','*'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
Serial.begin(9600);
}
void loop()
{
char key = keypad.getKey();
int x = (key-48);
if (key != NO_KEY)
{
Serial.println(x);
}
}
หน้าที่เข้าชม | 7,125,785 ครั้ง |
ผู้ชมทั้งหมด | 2,822,683 ครั้ง |
เปิดร้าน | 15 ก.ย. 2557 |
ร้านค้าอัพเดท | 6 ก.ย. 2568 |