以前の DoctorMX用のスイッチを作る という記事が、Arduino側の仕様がだいぶ変わってしまって通じなくなっていたので再掲。
今度は、Pololu astar32u4 microです。
スケッチはこちら。
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
#define BUTTON_PIN 12 | |
#define LED_PIN 13 | |
int reading; | |
int prevRead = HIGH; | |
void setup() { | |
pinMode(BUTTON_PIN, INPUT_PULLUP); | |
pinMode(LED_PIN,OUTPUT); | |
digitalWrite(LED_PIN,HIGH); | |
Keyboard.begin(); | |
} | |
void loop(){ | |
reading = digitalRead(BUTTON_PIN); | |
if(!reading){ | |
if(prevRead) { | |
Keyboard.press(KEY_DOWN_ARROW); | |
digitalWrite(LED_PIN,LOW); | |
delay(100); | |
Keyboard.releaseAll(); | |
digitalWrite(LED_PIN,HIGH); | |
} | |
} | |
prevRead = reading; | |
delay(10); | |
} |
コメント
コメントを投稿