Specifications of a 4x4 Membrane Keypad
Electrical Specifications:
- Circuit Voltage: 35V (DC), 100mA, 1W
- Contact Resistance: 10Ω ~ 500Ω (May vary depending on cable length and material used)
- Insulation Resistance: 100MΩ 100V
- Dielectric Withstand Voltage: 250VRms (50~60Hz 1 min)
- Contact Bounce: <= 5ms
- Lifespan: 1 million ON/OFF cycles
- Operating Temperature: -40 to +80 °C
Mechanical Specifications:
- Operating Force: Tactile: 170~397g (6~14oz)
- Travel Distance: Tactile: 0.6~1.5 mm
Environmental Parameters:
- Operating Temperature: -40 to +80 °C
- Humidity: 40% ~ 95%, 240 hours
- Vibration: Max 20G (10 ~~ 200 Hz, Mil-SLD-202 M204 Condition B)
Dimensions:
- Panel Size: 68 * 20 mm (For 1x4 keypad)
- Size: 77 x 70 x 0.8 mm (For 4x4 keypad)
Materials:
- Sheet: Polycarbonate
- Dome: Silicone
- Switch: Membrane
Connection:
- Connector: 7 pin 0.1" (2.54 mm) (For 1x4 keypad)
- Connector: 8 pin (Pitch 2.54mm) (For 4x4 keypad)
Notes:
- These specifications may vary depending on the model of 4x4 membrane keypad.
- Some 4x4 membrane keypads may have additional features such as backlights or special keys.
ตัวอย่างโค้ด Arduino สำหรับแป้นพิมพ์เมมเบรน 4x4
โค้ดตัวอย่างต่อไปนี้แสดงวิธีใช้แป้นพิมพ์เมมเบรน 4x4 กับ Arduino:
#include <Keypad.h>
const byte ROWS = 4; // จำนวนแถว
const byte COLS = 4; // จำนวนคอลัมน์
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; // หมายเลขขา Arduino สำหรับแถว
byte colPins[COLS] = {5, 4, 3, 2}; // หมายเลขขา Arduino สำหรับคอลัมน์
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600); // เริ่มการสื่อสารแบบอนุกรม
}
void loop() {
char key = keypad.getKey(); // อ่านปุ่มที่กด
if (key) {
Serial.print("ปุ่มที่กด: "); // พิมพ์ข้อความ "ปุ่มที่กด:"
Serial.println(key); // พิมพ์ปุ่มที่กด
}
}
คำอธิบายโค้ด:
- โค้ดนี้ใช้ไลบรารี
Keypad
จาก Arduino ซึ่งช่วยให้ใช้งานแป้นพิมพ์เมมเบรนได้ง่ายขึ้น
- นิยามตัวแปร
ROWS
และ COLS
เพื่อกำหนดจำนวนแถวและคอลัมน์ของแป้นพิมพ์
- นิยามตัวแปร
keys
เป็นอาร์เรย์สองมิติที่เก็บค่าปุ่มบนแป้นพิมพ์
- นิยามตัวแปร
rowPins
และ colPins
เป็นอาร์เรย์ที่เก็บหมายเลขขา Arduino ที่เชื่อมต่อกับแถวและคอลัมน์ของแป้นพิมพ์
- สร้างวัตถุ
Keypad
โดยใช้ฟังก์ชัน makeKeymap()
- ฟังก์ชัน
setup()
เริ่มการสื่อสารแบบอนุกรมที่ความเร็ว 9600 baud
- ฟังก์ชัน
loop()
ตรวจสอบปุ่มที่กดโดยใช้ฟังก์ชัน getKey()
ของวัตถุ Keypad
- if ปุ่มถูกกด จะพิมพ์ข้อความ "ปุ่มที่กด:" และค่าปุ่มบนหน้าจออนุกรม