Skip to content

Instantly share code, notes, and snippets.

@weldtype
Created June 14, 2017 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weldtype/f4de9839c43fbf09d2a204c7631d7003 to your computer and use it in GitHub Desktop.
Save weldtype/f4de9839c43fbf09d2a204c7631d7003 to your computer and use it in GitHub Desktop.
// 二線で三つのスイッチを読む
// 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