Created
June 2, 2016 05:41
-
-
Save yoggy/1e28e1d0e56047d29a402ac7146ff845 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <Keyboard.h> | |
int pin_button = 8; | |
int count = 0; | |
bool is_push_button = false; | |
void setup() { | |
pinMode(pin_button, INPUT_PULLUP); | |
Serial.begin(9600); | |
Keyboard.begin(); | |
} | |
void loop() { | |
check_button_status(); | |
} | |
void check_button_status() { | |
int val = digitalRead(pin_button); | |
if (val == 0) { | |
count ++; | |
} | |
else { | |
count = 0; | |
if (is_push_button == true) { | |
on_release_button(); | |
is_push_button = false; | |
} | |
} | |
if (count > 1000) { | |
if (is_push_button == false) { | |
on_push_button(); | |
is_push_button = true; | |
} | |
} | |
} | |
void on_push_button() { | |
Serial.println("push"); | |
// ここでボタンを押したときの処理をする | |
Keyboard.write('a'); | |
} | |
void on_release_button() { | |
Serial.println("release"); | |
// ここでボタンをはなしたときの処理をする | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment