-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuttonInput.cpp
More file actions
101 lines (96 loc) · 2.03 KB
/
buttonInput.cpp
File metadata and controls
101 lines (96 loc) · 2.03 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
Functions to handle button input on the Arduino.
*/
#include "Arduino.h"
#include "buttonInput.h"
#include "SNESpad.h"
#include "pins.h"
#include "gameplay.h"
// Returns the button being pressed by the user. If no button
// is being pressed, returns -1.
int getPressedColor()
{
// First update buttons states to make sure that we
// get the most recent information
updateButtonStates();
// Now, get the button that's been pressed. If multiple
// buttons are pressed, get the first one in order.
if (red_button_state)
{
return 0;
}
else if (green_button_state)
{
return 1;
}
else if (blue_button_state)
{
return 2;
}
else if (yellow_button_state)
{
return 3;
}
else
{
return -1;
}
}
// Updates the current state for all of the color buttons
void updateButtonStates()
{
int state = snes_pad.buttons();
red_button_state = state & SNES_A;
green_button_state = state & SNES_Y;
blue_button_state = state & SNES_X;
yellow_button_state = state & SNES_B;
}
// Checks to see if a certain button is being pressed
boolean isPressed(int color)
{
switch (color)
{
case 0:
if (red_button_state)
{
return true;
}
else
{
return false;
}
break;
case 1:
if (green_button_state)
{
return true;
}
else
{
return false;
}
break;
case 2:
if (blue_button_state)
{
return true;
}
else
{
return false;
}
break;
case 3:
if (yellow_button_state)
{
return true;
}
else
{
return false;
}
break;
default:
return false;
}
}