#include "DigiKeyboard.h" #define INT 2 #define CLK 1 #define DAT 0 static volatile uint8_t code; static volatile bool scf; void receiveCode() { code = 0; for(int i=0; i<8; i++) { while(digitalRead(CLK) == HIGH); code |= (digitalRead(DAT) << i); while(digitalRead(CLK) == LOW); } if(code & 0x80) { switch(code) { case 0xe5: // 2ndF scf = !scf; break; case 0x81: // ( DigiKeyboard.sendKeyPress(0x26, MOD_SHIFT_LEFT); break; case 0x82: // ) DigiKeyboard.sendKeyPress(0x27, MOD_SHIFT_LEFT); break; case 0xe2: // LeftAlt→カナ DigiKeyboard.sendKeyPress(0xe2, MOD_ALT_LEFT); break; case 0xA3: // ^→yx DigiKeyboard.sendKeyPress(0x23, MOD_SHIFT_LEFT); break; default: if(scf) DigiKeyboard.sendKeyPress(code & 0x7f, MOD_SHIFT_LEFT | MOD_CONTROL_LEFT); else DigiKeyboard.sendKeyPress(code & 0x7f, MOD_CONTROL_LEFT); } } else { if(scf) DigiKeyboard.sendKeyPress(code, MOD_SHIFT_RIGHT); else DigiKeyboard.sendKeyPress(code, 0); } DigiKeyboard.sendKeyPress(0, 0); while(digitalRead(INT) == 0); } void setup() { pinMode(INT, INPUT_PULLUP); pinMode(CLK, INPUT_PULLUP); pinMode(DAT, INPUT); scf = false; attachInterrupt(0, receiveCode, FALLING); } void loop() { // USBキーボードと認識されるのに適当なウェイトが必要 DigiKeyboard.delay(1000); }