Teensy 3.1 Button problems

sd846

New member
Hey Everybody,
I am completely new to teensy and arduino so please excuse any of my mistakes. Anyway im trying use my teensy 3.1 as a joystick, i currently have 2 buttons connected to it(starting out simple) and im using the microsoft game properties to test it. The problem is when i press one of the buttons it shows the button working but it also changes all of the axis controls and the hat control. I am Running windows 10. I have the pictures of the before and after attached.

Here is the code:
#include <Bounce.h>

// Create Bounce objects for each button. The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button0 = Bounce(0, 10);
Bounce button1 = Bounce(1, 10); // 10 = 10 ms debounce time

void setup() {
// Configure the pins for input mode with pullup resistors.
// The pushbuttons connect from each pin to ground. When
// the button is pressed, the pin reads LOW because the button
// shorts it to ground. When released, the pin reads HIGH
// because the pullup resistor connects to +5 volts inside
// the chip. LOW for "on", and HIGH for "off" may seem
// backwards, but using the on-chip pullup resistors is very
// convenient. The scheme is called "active low", and it's
// very commonly used in electronics... so much that the chip
// has built-in pullup resistors!
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);

}

void loop() {
// Update all the buttons. There should not be any long
// delays in loop(), so this runs repetitively at a rate
// faster than the buttons could be pressed and released.
button0.update();
button1.update();


// Check each button for "falling" edge.
// Update the Joystick buttons only upon changes.
// falling = high (not pressed - voltage from pullup resistor)
// to low (pressed - button connects pin to ground)
if (button0.fallingEdge()) {
Joystick.button(1, 1);
}
if (button1.fallingEdge()) {
Joystick.button(2, 1);
}


// Check each button for "rising" edge
// Update the Joystick buttons only upon changes.
// rising = low (pressed - button connects pin to ground)
// to high (not pressed - voltage from pullup resistor)
if (button0.risingEdge()) {
Joystick.button(1, 0);
}
if (button1.risingEdge()) {
Joystick.button(2, 0);
}


}
 

Attachments

  • before.jpg
    before.jpg
    58 KB · Views: 203
  • After.jpg
    After.jpg
    57.2 KB · Views: 189
Any chance you could try on a pre-10 version of Windows?

I just got my copy of 10 today... haven't installed it yet. Will do soon.
 
I just tried it on windows 8.1 (Had my laptop near me) and unfortunately it does the same thing
 
Ok, I've managed to reproduce the problem you're seeing on Windows 10. Well, at least I think I've got the same thing here.

After programming Teensy and opening JOY.CPL, I see this:

Capture1.PNG
(click for full size)

Then, as soon as I press a button, the X-Y position and 4 axes go to zero, as well as the button indicates pressed.

Capture2.PNG
(click for full size)

This may seem as if something is wrong on Teensy, causing the buttons to interfere with the axes. However, there is actually nothing wrong on the Teensy side.

The problem is Windows 10 is just making up default data before it receives any communication from Teensy. Before that first button press, Windows has never received any info from Teensy, so it has absolutely no idea what the X, Y, Z, Zr and Slider position are. It's just defaulting to showing them at the center of their range.

If you never set those parameters, Teensy defaults to zero (on a scale of 0 to 1023). Perhaps Teensy should instead default to 512? Obviously Windows is assuming the default is 512, before it gets any real info.

Anyway, if you want the Windows joystick control panel to respond the way you expect, all you need to do is add a little code inside setup(), like this:

Code:
    Joystick.Z(512);  // same as Windows default
 
I am so glad you able to reproduce it, for a little bit i thought i was going crazy lol. Your solution works perfectly, thank you so much paul for your help.
 
Hello guys,
i have the same problem, but where i have to put in that code, please?

This don't work.

Thank you very much.

Manuel
#include <Bounce.h>

// Create Bounce objects for each button. The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button0 = Bounce(0, 10);
Bounce button1 = Bounce(1, 10); // 10 = 10 ms debounce time
Joystick.Z(512); // same as Windows default
void setup() {
// Configure the pins for input mode with pullup resistors.
// The pushbuttons connect from each pin to ground. When
// the button is pressed, the pin reads LOW because the button
// shorts it to ground. When released, the pin reads HIGH
// because the pullup resistor connects to +5 volts inside
// the chip. LOW for "on", and HIGH for "off" may seem
// backwards, but using the on-chip pullup resistors is very
// convenient. The scheme is called "active low", and it's
// very commonly used in electronics... so much that the chip
// has built-in pullup resistors!
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);

}

void loop() {
// Update all the buttons. There should not be any long
// delays in loop(), so this runs repetitively at a rate
// faster than the buttons could be pressed and released.
button0.update();
button1.update();


// Check each button for "falling" edge.
// Update the Joystick buttons only upon changes.
// falling = high (not pressed - voltage from pullup resistor)
// to low (pressed - button connects pin to ground)
if (button0.fallingEdge()) {
Joystick.button(1, 1);
}
if (button1.fallingEdge()) {
Joystick.button(2, 1);
}


// Check each button for "rising" edge
// Update the Joystick buttons only upon changes.
// rising = low (pressed - button connects pin to ground)
// to high (not pressed - voltage from pullup resistor)
if (button0.risingEdge()) {
Joystick.button(1, 0);
}
if (button1.risingEdge()) {
Joystick.button(2, 0);
}


}
 

Anyway, if you want the Windows joystick control panel to respond the way you expect, all you need to do is add a little code inside setup(), like this:

Code:
    Joystick.Z(512);  // same as Windows default

Hello guys,
i have the same problem, but where i have to put in that code, please?

This don't work.

Thank you very much.

Manuel

Based on Paul's post:

Code:
 void setup() {
    Joystick.Z(512);  // same as Windows default
    // … other setup code
 }
 
Is that correct?

#include <Bounce.h>

// Create Bounce objects for each button. The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button0 = Bounce(0, 10);
Bounce button1 = Bounce(1, 10); // 10 = 10 ms debounce time
void setup() {
Joystick.Z(512); // same as Windows default

// Configure the pins for input mode with pullup resistors.
// The pushbuttons connect from each pin to ground. When
// the button is pressed, the pin reads LOW because the button
// shorts it to ground. When released, the pin reads HIGH
// because the pullup resistor connects to +5 volts inside
// the chip. LOW for "on", and HIGH for "off" may seem
// backwards, but using the on-chip pullup resistors is very
// convenient. The scheme is called "active low", and it's
// very commonly used in electronics... so much that the chip
// has built-in pullup resistors!
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);

}

void loop() {
// Update all the buttons. There should not be any long
// delays in loop(), so this runs repetitively at a rate
// faster than the buttons could be pressed and released.
button0.update();
button1.update();


// Check each button for "falling" edge.
// Update the Joystick buttons only upon changes.
// falling = high (not pressed - voltage from pullup resistor)
// to low (pressed - button connects pin to ground)
if (button0.fallingEdge()) {
Joystick.button(1, 1);
}
if (button1.fallingEdge()) {
Joystick.button(2, 1);
}


// Check each button for "rising" edge
// Update the Joystick buttons only upon changes.
// rising = low (pressed - button connects pin to ground)
// to high (not pressed - voltage from pullup resistor)
if (button0.risingEdge()) {
Joystick.button(1, 0);
}
if (button1.risingEdge()) {
Joystick.button(2, 0);
}


}
 
With that code, i have the same problem again.
After press the first button, you see that.
View attachment 15280

Yes, sometimes blind copy&paste without trying to understand what it does, does not help..

first, try this:
Code:
void setup() {
// same as Windows default
Joystick.Z(512);
Joystick.X(512);
Joystick.Y(512);
Joystick.Zrotate(512);
Joystick.sliderLeft(512);
Joystick.sliderRight(512);
//Joystick.slider(512);
[...]
.. this uses the Windows defaults for the other values, too
To see the change, click on "Auf Standard zurücksetzen"
2018-12-04 20_41_00-Window.png
 
Last edited:
After that, all buttons in the middle or off, but if you click one time, the + are upper left and the round-button are up.
I want only buttons on my teensyLC.
 
Nö,bei mir nicht. Hast auf "Auf Standard zurücksetzen" geklickt? Hast du das neue Programm überhaupt auf den Teensy übertragen?
 
something is wrong.. perhaps sleep a night and try it again. :)
sorry, I don't know what the problem is now. Ausserdem läuft dr who im TV.
 
sorry to necro this thread but I noticed the hat is showing a forward activation. Why is that? I ask because I am having the same oddity and it is causing my tactical analysis flight appplication (tacview) to continually scroll left unless I disconnect the teensy.
 
Back
Top