Permalink
Browse files

removed nonworking debounce code

  • Loading branch information...
1 parent a779283 commit 6d2474aca7d7e5e21faa0f5a71c99f80dc4bf530 @ladyada ladyada committed Apr 9, 2010
Showing with 7 additions and 62 deletions.
  1. +7 −62 teensySNES_test1/teensySNES_test1.pde
@@ -26,8 +26,6 @@ byte keys[] = {KEY_U, KEY_R, KEY_D, KEY_L, KEY_ENTER, KEY_TAB, KEY_B, KEY_A, KEY
#define NUMBUTTONS sizeof(buttons)
-// we will track if a button is just pressed, just released, or 'currently pressed'
-volatile byte pressed[NUMBUTTONS], justpressed[NUMBUTTONS], justreleased[NUMBUTTONS];
void setup()
{
@@ -40,11 +38,6 @@ void setup()
pinMode(buttons[i], INPUT_PULLUP);
}
-
- //Zero the SNES controller button keys:
- for (byte i=0; i< NUMBUTTONS; i++) {
- pressed[i] = justpressed[i] = justreleased[i] = 0;
- }
//Uncomment this line to debug the acceleromter values:
// Serial.begin();
@@ -57,7 +50,6 @@ void loop()
// //debugging the start button...
digitalWrite ( pinLEDOutput, digitalRead(pinBtnStart));
- check_switches();
//Progess the SNES controller buttons to send keystrokes.
fcnProcessButtons();
@@ -69,11 +61,14 @@ void fcnProcessButtons()
static long currentkey = 0;
byte nothingpressed = 1;
+ // run through all the buttons
for (byte i = 0; i < NUMBUTTONS; i++) {
- // Serial.print(i, DEC); Serial.print(" -> "); Serial.println(pressed[i], HEX);
- if (pressed[i]) {
- nothingpressed = 0;
+
+ // are any of them pressed?
+ if (! digitalRead(buttons[i])) {
+ nothingpressed = 0; // at least one button is pressed!
+ // if its a new button, release the old one, and press the new one
if (currentkey != keys[i]) {
Keyboard.set_key1(0);
Keyboard.send_now();
@@ -90,61 +85,11 @@ void fcnProcessButtons()
}
if (nothingpressed) {
+ // release all keys
Keyboard.set_key1(0);
Keyboard.send_now();
}
}
-void check_switches()
-{
- static byte previousstate[NUMBUTTONS];
- static byte currentstate[NUMBUTTONS];
- static long lasttime;
- byte index;
-
- if (millis() < lasttime) {
- // we wrapped around, lets just try again
- lasttime = millis();
- }
-
- if ((lasttime + DEBOUNCE) > millis()) {
- // not enough time has passed to debounce
- return;
- }
- // ok we have waited DEBOUNCE milliseconds, lets reset the timer
- lasttime = millis();
-
- for (index = 0; index < NUMBUTTONS; index++) {
- justpressed[index] = 0; // when we start, we clear out the "just" indicators
- justreleased[index] = 0;
-
- currentstate[index] = digitalRead(buttons[index]); // read the button
-
- /*
- Serial.print(index, DEC);
- Serial.print(": cstate=");
- Serial.print(currentstate[index], DEC);
- Serial.print(", pstate=");
- Serial.print(previousstate[index], DEC);
- Serial.print(", press=");
- */
-
- if (currentstate[index] == previousstate[index]) {
- if ((pressed[index] == LOW) && (currentstate[index] == LOW)) {
- // just pressed
- justpressed[index] = 1;
- }
- else if ((pressed[index] == HIGH) && (currentstate[index] == HIGH)) {
- // just released
- justreleased[index] = 1;
- }
- pressed[index] = !currentstate[index]; // remember, digital HIGH means NOT pressed
- }
- // Serial.println(pressed[index], DEC);
- previousstate[index] = currentstate[index]; // keep a running tally of the buttons
- }
-}
-
-

0 comments on commit 6d2474a

Please sign in to comment.