Created
June 14, 2017 20:45
-
-
Save weldtype/f4de9839c43fbf09d2a204c7631d7003 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 二線で三つのスイッチを読む | |
// 2017/06/12 | |
// edy | |
// | |
#include "Keyboard.h" | |
int analogPin = A0; | |
int ADCresult = 0; | |
int SW = 0; | |
void setup() { | |
Keyboard.begin(); | |
analogReference(DEFAULT); | |
} | |
void loop() { | |
SW = readSW(); | |
switch (SW) { | |
case 5: // open | |
break; | |
case 4: // all off | |
break; | |
case 3: tab_key(); | |
break; | |
case 2: shift_tab_key(); | |
break; | |
case 1: | |
break; | |
case 0: // short | |
break; | |
default: | |
break; | |
} | |
delay(100); | |
} | |
int readSW(void) | |
{ | |
int ADCresult = analogRead(analogPin); | |
return (ADCresult + 102) / 205; | |
} | |
void tab_key(void) | |
{ | |
Keyboard.press(KEY_TAB); | |
delay(100); | |
Keyboard.releaseAll();// Keyboard.release(KEY_TAB); | |
while (readSW() == 3) { | |
delay(100); | |
} | |
} | |
void shift_tab_key(void) | |
{ | |
Keyboard.press(KEY_LEFT_SHIFT); | |
Keyboard.press(KEY_TAB); | |
delay(100); | |
Keyboard.releaseAll(); | |
while (readSW() == 2) { | |
delay(100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment