-
Notifications
You must be signed in to change notification settings - Fork 1
/
scopekeyboard.cpp
50 lines (29 loc) · 934 Bytes
/
scopekeyboard.cpp
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
46
47
48
49
50
#include "scopekeyboard.h"
#include "arduino.h"
int last_key_confirmed = 0;
void keyboardSetup() {
// initialize the pushbutton pin as an input:
pinMode(buttonUp, INPUT_PULLUP);
pinMode(buttonDown, INPUT_PULLUP);
pinMode(buttonLeft, INPUT_PULLUP);
pinMode(buttonRight, INPUT_PULLUP);
pinMode(buttonCenter, INPUT_PULLUP);
}
//is a key pressed?
void keyboardCheck()
{
int presentKeyPressed = 0;
if (digitalRead(buttonLeft) == 0) presentKeyPressed = buttonLeft;
if (digitalRead(buttonRight) == 0) presentKeyPressed = buttonRight;
if (digitalRead(buttonUp) == 0) presentKeyPressed = buttonUp;
if (digitalRead(buttonDown) == 0) presentKeyPressed = buttonDown;
if (digitalRead(buttonCenter) == 0) presentKeyPressed = buttonCenter;
last_key_confirmed = presentKeyPressed;
}
int keyboardGetButton()
{
keyboardCheck();
int key = last_key_confirmed;
last_key_confirmed = 0;
return key;
}