Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
// 二線で三つのスイッチを読む
// 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