-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvimpedal.ino
45 lines (34 loc) · 1001 Bytes
/
vimpedal.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
Vim pedal by Aleksey Kurepin
For the Arduino Leonardo and Micro.
Sends a `Esc` and `i` when a pedal is pressed
and `Esc` when a pedal is released.
The circuit:
* optical sensor attached to pin 9
created 24 Oct 2011
modified 27 Mar 2012
by Tom Igoe
modified 11 Nov 2013
by Scott Fitzgerald
modified 29 Jul 2014
by Aleksey Kurepin
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/KeyboardMessage
*/
const int buttonPin = 9; // input pin for pushbutton
int previousButtonState = HIGH; // for checking the state of a pushButton
void setup() {
pinMode(buttonPin, INPUT);
Keyboard.begin();
}
void loop() {
int buttonState = digitalRead(buttonPin);
if ((buttonState != previousButtonState) && (buttonState == HIGH)) {
Keyboard.write(KEY_ESC);
Keyboard.write("i");
}
else if ((buttonState != previousButtonState) && (buttonState == LOW)) {
Keyboard.write(KEY_ESC);
}
previousButtonState = buttonState;
}