Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Bounce problem on Pin 0 of Teensy++ 2.0

  1. #1

    Bounce problem on Pin 0 of Teensy++ 2.0

    What am I missing with the following code?

    Switches are connected between pins 0-5 (D0-D5) and ground, on a Teensy++ 2.0

    grounding pin 0 does nothing
    grounding pin 1 press key_0
    grounding pin 2 presses key_1
    etc.

    It's almost as if the pin numbers are starting at 1, but I have buttons on pins 18 -26 that work ok.

    Code:
    #include <Bounce.h>
    
    Bounce joy1Up = Bounce(0,10);				// joystick 1 up pin
    Bounce joy1Down = Bounce(1,10);				// joystick 1 down pin
    Bounce joy1Left = Bounce(2,10);				// joystick 1 left pin
    Bounce joy1Right = Bounce(3,10);			// joystick 1 right pin
    Bounce joy2Up = Bounce(4,10);				// joystick 2 up pin
    Bounce joy2Down = Bounce(5,10);	
    
    void setup()
    {
    	// set up button and joystick pins
    	for(int i=0; i <6; i++)
    	{
    		pinMode(i,INPUT_PULLUP);
    	}
    }
    
    void loop()
    {
     	// joystick 1 up : Y AXIS +
    	if (joy1Up.update())
    	{
    		if (joy1Up.fallingEdge())
    		{
    			Keyboard.press(KEY_0);
    		}
    		if (joy1Up.risingEdge())
    		{
    			Keyboard.release(KEY_0);
    		}	
    	}
    	// joystick 1 down : Y AXIS -
    	if (joy1Down.update())
    	{
    		if (joy1Down.fallingEdge())
    		{
    			Keyboard.press(KEY_1);
    		}
    		if (joy1Down.risingEdge())
    		{
    			Keyboard.release(KEY_1);
    		}	
    	}
    	// joystick 1 left : X AXIS -
    	if (joy1Left.update())
    	{
    		if (joy1Left.fallingEdge())
    		{
    			Keyboard.press(KEY_2);
    		}
    		if (joy1Left.risingEdge())
    		{
    			Keyboard.release(KEY_2);
    		}	
    	}
    	// joystick 1 right : X AXIS +
    	if (joy1Right.update())
    	{
    		if (joy1Right.fallingEdge())
    		{
    			Keyboard.press(KEY_3);
    		}
    		if (joy1Right.risingEdge())
    		{
    			Keyboard.release(KEY_3);
    		}	
    	}
    	// joystick 2 up : Z AXIS +
    	if (joy2Up.update())
    	{
    		if (joy2Up.fallingEdge())
    		{
    			Keyboard.press(KEY_4);
    		}
    		if (joy2Up.risingEdge())
    		{
    			Keyboard.release(KEY_4);
    		}	
    	}
    	// joystick 2 down : Z AXIS -
    	if (joy2Down.update())
    	{
    		if (joy2Down.fallingEdge())
    		{
    			Keyboard.press(KEY_5);
    		}
    		if (joy2Down.risingEdge())
    		{
    			Keyboard.release(KEY_5);
    		}	
    	} 
    }
    Regards,

    Les

  2. #2
    Ignore that last post, I was forget about that sneaky pin 27!

    DOH!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •