
이전 글: https://newtlekim.tistory.com/7
무선 블루투스 키보드를 만들기 위해서, 위 글을 반드시 보고오는게 좋습니다. 중복된 내용은 과감히 뺐습니다.

회로는 아래와 같이 설계하였습니다.

PCB제작파일 Gerber파일은 아래 클릭해서 다운받을 수 있습니다.
Gerber_BLE_keypad_PCB_keypad_keyboard.zip
0.02MB
아래 링크들어가셔서 다운받은 Gerber파일 업로드하고 주문하면 쉽게 PCB를 받을 수 있습니다.
https://jlcpcb.com/kr?from=newtle_kim1
3D모델파일은 아래 클릭해서 다운받을 수 있습니다.
BLEKP_cover.stl
2.30MB
BLEKP_top_plate.stl
0.50MB
BLEKP_main_body.stl
1.23MB
cover_acrylic_for_lasercutting.dxf
0.00MB
아두이노 IDE 설치하고, 붙여넣습니다.
#include <BleKeyboard.h>
const uint8_t rowPins[5] = {23, 22, 21, 19, 18};
const uint8_t colPins[4] = {33, 25, 26, 27};
// 일반 키로 변경 (문자/기호 직접 입력)
const uint8_t keymap[5][4] = {
{'0', 0, '.', 0}, // ROW 0
{'1', '2', '3', KEY_RETURN}, // ROW 1 (Enter)
{'4', '5', '6', 0}, // ROW 2
{'7', '8', '9', '+'}, // ROW 3
{KEY_BACKSPACE, '/', '*', '-'} // ROW 4
};
BleKeyboard btKeyboard("NewtleKeypad");
bool keyPressed[5][4] = {false}; // 눌림 상태 추적
void setup() {
Serial.begin(115200);
for (uint8_t i = 0; i < 4; i++) {
pinMode(colPins[i], INPUT_PULLUP);
}
for (uint8_t i = 0; i < 5; i++) {
pinMode(rowPins[i], OUTPUT);
digitalWrite(rowPins[i], HIGH); // 기본 HIGH
}
btKeyboard.begin();
Serial.println("BLE Keyboard ready. Waiting for connection...");
}
void loop() {
if (btKeyboard.isConnected()) {
for (uint8_t row = 0; row < 5; row++) {
digitalWrite(rowPins[row], LOW);
delayMicroseconds(5);
for (uint8_t col = 0; col < 4; col++) {
uint8_t pin = colPins[col];
uint8_t key = keymap[row][col];
if (key == 0) continue; // 빈 칸
bool currentState = digitalRead(pin) == LOW;
if (currentState && !keyPressed[row][col]) {
btKeyboard.press(key);
keyPressed[row][col] = true;
Serial.printf("Pressed [%d,%d] keycode: %d\n", row, col, key);
}
if (!currentState && keyPressed[row][col]) {
btKeyboard.release(key);
keyPressed[row][col] = false;
Serial.printf("Released [%d,%d] keycode: %d\n", row, col, key);
}
}
digitalWrite(rowPins[row], HIGH);
}
} else {
Serial.println("BLE not connected...");
delay(500);
}
delay(10);
}
보드는 ESP32 Dev Module 을 설정하고, 아두이노 IDE 상단메뉴에 있는 Tools에서 설정을 아래와 같이 하고 컴파일 합니다.
