Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
弐寺コントローラー自作したときに書いたやつ
#include "HID-Project.h"
#define KEY_1 2
#define KEY_2 3
#define KEY_3 4
#define KEY_4 5
#define KEY_5 6
#define KEY_6 7
#define KEY_7 8
#define KEY_START 9
#define KEY_VEFX 15
#define KEY_CODE_1 'z'
#define KEY_CODE_2 's'
#define KEY_CODE_3 'x'
#define KEY_CODE_4 'd'
#define KEY_CODE_5 'c'
#define KEY_CODE_6 'f'
#define KEY_CODE_7 'v'
#define KEY_CODE_START KEY_TAB
#define KEY_CODE_VEFX KEY_BACKSPACE
#define KEY_CODE_ESC KEY_ESC
#define push(n) NKROKeyboard.add(n)
#define rpush(n) NKROKeyboard.remove(n)
#define send() NKROKeyboard.send()
void setup() {
pinMode(KEY_1, INPUT_PULLUP);
pinMode(KEY_2, INPUT_PULLUP);
pinMode(KEY_3, INPUT_PULLUP);
pinMode(KEY_4, INPUT_PULLUP);
pinMode(KEY_5, INPUT_PULLUP);
pinMode(KEY_6, INPUT_PULLUP);
pinMode(KEY_7, INPUT_PULLUP);
pinMode(KEY_START, INPUT_PULLUP);
pinMode(KEY_VEFX, INPUT_PULLUP);
NKROKeyboard.begin();
}
void loop() {
if(digitalRead(KEY_1) == LOW) push(KEY_CODE_1); else rpush(KEY_CODE_1);
if(digitalRead(KEY_2) == LOW) push(KEY_CODE_2); else rpush(KEY_CODE_2);
if(digitalRead(KEY_3) == LOW) push(KEY_CODE_3); else rpush(KEY_CODE_3);
if(digitalRead(KEY_4) == LOW) push(KEY_CODE_4); else rpush(KEY_CODE_4);
if(digitalRead(KEY_5) == LOW) push(KEY_CODE_5); else rpush(KEY_CODE_5);
if(digitalRead(KEY_6) == LOW) push(KEY_CODE_6); else rpush(KEY_CODE_6);
if(digitalRead(KEY_7) == LOW) push(KEY_CODE_7); else rpush(KEY_CODE_7);
if(digitalRead(KEY_START) == LOW && digitalRead(KEY_VEFX) == LOW) {
push(KEY_CODE_ESC);
} else {
rpush(KEY_CODE_ESC);
if(digitalRead(KEY_START) == LOW) push(KEY_CODE_START); else rpush(KEY_CODE_START);
if(digitalRead(KEY_VEFX) == LOW) push(KEY_CODE_VEFX); else rpush(KEY_CODE_VEFX);
}
send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment