forked from NattyBumppo/Simon-Clone-for-Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SNESpad.cpp
executable file
·63 lines (54 loc) · 1.69 KB
/
SNESpad.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
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
SNESpad - Arduino library for interfacing with an SNES joystick
Version: 1.3 (11/12/2010) - get rid of shortcut constructor - seems to be broken
Version: 1.2 (05/25/2009) - put pin numbers in constructor (Pascal Hahn)
Version: 1.1 (09/22/2008) - fixed compilation errors in arduino 0012 (Rob Duarte)
Version: 1.0 (09/20/2007) - Created (Rob Duarte)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITSNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SNESpad.h"
#include "Arduino.h"
// constructor
SNESpad::SNESpad(int strobe, int clock, int data)
: m_strobe (strobe),
m_clock (clock),
m_data (data)
{
pinMode(strobe, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(data, INPUT);
}
int SNESpad::buttons(void)
{
int ret = 0;
byte i;
strobe();
for (i = 0; i < 16; i++) {
ret |= shiftin() << i;
}
return ~ret;
}
void SNESpad::strobe(void)
{
digitalWrite(m_strobe,HIGH);
delayMicroseconds(12);
digitalWrite(m_strobe,LOW);
}
int SNESpad::shiftin(void)
{
int ret = digitalRead(m_data);
delayMicroseconds(12);
digitalWrite(m_clock,HIGH);
delayMicroseconds(12);
digitalWrite(m_clock,LOW);
return ret;
}