Teensy 2.0 Help: Can't Program for Left, Right, Enter

Hi everyone,

I know there's a ton of info out there and I've found some that may help. But I've also found others that are really confusing. I'm not a programmer but I have successfully programmed one project a year ago. I'm back to modify and add to my original program. The problem is that I don't know what comes next as the original code I used was someone else's. I understand it, but writing new blocks of code is a little over my head. I was wondering if you guys can help?

Basically, the code below is just a single button that returns a space to the computer. It's connected via USB. The controller is a Teensy 2.0. From what I've read, the Teensy can support more than one button. So for my next project, I'd like to add the Left, Right and Enter buttons. What's the best and most efficient way to add the code into my existing script?

/*
*button.pde
*/

void setup(){
Serial.begin(9600);
pinMode(0, INPUT_PULLUP);
delay(5000);
}

void loop() {
if (digitalRead(0) == HIGH) {
delay(10);
} else {
Keyboard.print(" "); // button push emulates a physical spacebar push
delay(500);
}
//delay(10);
}

I think I got it. I got it to compile but I haven't physically tested it yet 'coz I don't have a USB A-B cable. "wonk wonk wonk" LOL!

But maybe you guys can confirm for me as I go out and buy one.

/*
*button.pde
*/

void setup()
{
Serial.begin(9600);
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
delay(5000);
}

void loop()
// start of condition for SPACEBAR, pin 0
{
if (digitalRead(0) == HIGH)
{
delay(10);
}

else

{
Keyboard.print(" "); // button push emulates a physical SPACEBAR push
delay(500);
}

// start of condition for LEFT BUTTON, pin 1
if (digitalRead(1) == HIGH)
{
delay(10);
}

else

{
Keyboard.print(KEY_LEFT); // button push emulates a physical LEFT BUTTON push
delay(500);
}

// start of condition for RIGHT BUTTON, pin 2
if (digitalRead(2) == HIGH)
{
delay(10);
}

else

{
Keyboard.print(KEY_RIGHT); // button push emulates a physical RIGHT BUTTON push
delay(500);
}

// start of condition for ENTER BUTTON, pin 3
if (digitalRead(3) == HIGH)
{
delay(10);
}

else

{
Keyboard.print(KEY_ENTER); // button push emulates a physical ENTER BUTTON push
delay(500);
}

}

Yeah, no. That code isn't working. I get the space to work but pressing the other three hits the return key indefinitely until I hit another key, or goes right or left indefinitely until I hit something else. I guess I'm close but I'm not sure how to fix it.

/*
*button.pde
*/

void setup()
{
Serial.begin(9600);
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
delay(5000);
}

void loop()
// start of condition for SPACEBAR, pin 0
{
if (digitalRead(0) == HIGH)
{
delay(10);
}

else

{
Keyboard.print(" "); // button push emulates a physical SPACEBAR push
delay(500);
}

// start of condition for LEFT BUTTON, pin 1
if (digitalRead(1) == HIGH)
{
delay(10);
}

else

{
Keyboard.press(KEY_LEFT_ARROW); // button push emulates a physical LEFT BUTTON push
delay(500);
}

// start of condition for RIGHT BUTTON, pin 2
if (digitalRead(2) == HIGH)
{
delay(10);
}

else

{
Keyboard.press(KEY_RIGHT_ARROW); // button push emulates a physical RIGHT BUTTON push
delay(500);
}

// start of condition for ENTER BUTTON, pin 3
if (digitalRead(3) == HIGH)
{
delay(10);
}

else

{
Keyboard.press(KEY_ENTER); // button push emulates a physical ENTER BUTTON push
delay(500);
}

}

Figured it out.

I needed the keyboard.releaseall();