Special Aircraft Service

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 4 5 6 [7]   Go Down

Author Topic: Mike's new project  (Read 21001 times)

0 Members and 5 Guests are viewing this topic.

Zechsau

  • member
  • Offline Offline
  • Posts: 4
Re: Mike's new project
« Reply #72 on: March 10, 2021, 03:02:11 PM »

Back with a smaller update.

Controlling LEDs with joystickbuttons turns out to be quite the job. A little recap of what I did and had to abandon again.

At first I thought it'll be enough to get a wire to the respective row pins, but that didn't work. Reason: the matrix works with pulses (are to be found within in the code) not with the much simpler but slower voltage changes. Reason being that the chip is able to poll the whole matrix several times per millisecond when using pulses. For those who are interested in that, I'll have short explanation at the end of this post. Finding out the matrix or the so called event listener works with pulses inhibited me from using any further hardware solution for example transistors in order to get my LEDs working when the intended buttons are pushed.

@Mike: maybe you can enlighten me. I thought I can use the exact pin 'location' of each switch by the coordinates of rowPins and columnPins. Each time a Button is pressed, at least 2 specific pins used for the matrix are pulled to ground due to the pulses. That is the moment, the eventlistener implemented into the code registers a buttonpress and forwards that to the usb/pc. My idea was to use these coordinates to control my LED states similar to 'if pinColumnXYZ and pinRowXYZ are LOW, change LEDstate' (simplified so everyone can follow me here, if I have a working code I'll post that, ofcourse). Do you know of any way, to use the already built in eventlistener or do i have to write one myself and connect that to the existing code? Thanks for your answer in advance.

Cheers, Paul

P.S.: for those interested: The buttonmatrix consists of rows and pins, as shown in Mike's earlier posts. Each button terminal is attached to one 'row' and one 'column'. Theoretically, you can do any number of rows combined with any number of columns, as long as these can connect to your controllerboard. The benefit is that you can work 80 buttons (for Mike's example) with only 18 pins in total. If you wired each pin conventionally to each switch you'd need at least 80 pins, and that is a HUGE board. But i'm trailing off. By having all buttons arranged in a matrix where some are connected to rows and some to columns, you could easily distinguish each button. Basic state for colums AND rows is HIGH. Now if both pins are HIGH, how does the Teensy read a button press? The teensy sets the columns to a LOW pulse. One after the other. That happens so fast, that virtually it happens simultaneously on all column pins. If a button is pressed, while the LOW pulse is on the same column as pressed button, the teensy registers a LOW state and thus registers a buttonpress. As mentioned before this happens so fast, virutally all buttonpresses and even simultaneous buttonpresses are registered at same time, although technically one after the other. That speed of the LOW pulses is the problem I ran into when trying to hook in a 'listeneing' wire physically. It just doesn't work that way without the proper routine.
Logged

SAS~Storebror

  • Editor
  • member
  • Offline Offline
  • Posts: 23884
  • Taking a timeout
    • STFU
Re: Mike's new project
« Reply #73 on: March 11, 2021, 03:36:15 AM »

Hi Paul,

I have turned the rather general box design into something very customized for my case, where besides others changes, such an LED thing is implemented now as well.
I've added 3 LEDs to my board:
  • A blue LED which will flash for 10 seconds whenever there's some activity on the box.
  • A yellow LED indicating that an axis position reached it's end deadzone.
  • A green LED indicating a pressed button.

Furthermore (here it becomes a bit tricky), I've changed to box so that it can act in two different modes:
  • "Two controller" mode, which is the default, to be used for IL-2 1946.
  • "Single controller" mode, which can be toggled by holding two switches in opposite direction at the same time, to be used in other games like e.g. MSFS 2020.

You can find the most recent sourcecode snapshot attached to this post.
Watch out for e.g. the green LED handling, it's all about remembering the time when a button got pressed, and keeping the LED lit until a timeout elapses.

]cheers[
Mike
Logged
Don't split your mentality without thinking twice.

Zechsau

  • member
  • Offline Offline
  • Posts: 4
Re: Mike's new project
« Reply #74 on: March 21, 2021, 09:45:20 AM »

Thanks for the updated files, Mike!

I still have my problem to assign one specific button to light up one specific LED.Even your Sketch for the green LED doesn't work for me.

To get a bit more concise here: I want Button 65 (no 25 on Device 2) to deactivate the LED1 on Pin 22. My Problem is that I can't get the Arduino to recognize one specific buttonpress. I had an idea of using the eventlistener and the implemented getButtons function, yet that didn't work either.

 If I set the Buttonindex from your codesample to i == 65 instead of  i < 72, nothing happens. The device gets recognized by windows as well as the buttonpress itself. Even changing the code to work with button 25 just in case, nothing happens. Further I can't use your full codesample as you have the two-device mode implemented, and to be honest I don't want to include that level of complexety to my dad's device.

Just wanted to keep you posted.

I'll head back into all the forums trying to find a solution here.

Cheers, Paul
Logged

SAS~Storebror

  • Editor
  • member
  • Offline Offline
  • Posts: 23884
  • Taking a timeout
    • STFU
Re: Mike's new project
« Reply #75 on: March 21, 2021, 11:33:35 AM »

Not sure where the problem is honestly.
From my script, the LEDs are on Pins 24/25/26 (B4/B5/B6) (Blue/Yellow/Red).
In the loop() method, buttons get checked in the "buttonmatrix.getButtons()" call.
Whenever a button gets pressed, the Event handler "void buttonEvent(ButtonEvent listIndex)" will get called.
You can check the "buttonmatrix.button[listIndex].bindex" property for the index of the pressed button.
If that index matches your button number (note: The index is not necessarily the same number like what Windows shows you, it's a try&error thing after all), you should take note of the current time and add a few milliseconds to it (see "ledTime" filed in my script), turn on the LED of choice, and then in the loop() method check if the current time against the stored "ledTime" and if it's larger, turn off the LED again.

]cheers[
Mike
Logged
Don't split your mentality without thinking twice.
Pages: 1 ... 4 5 6 [7]   Go Up
 

Page created in 0.038 seconds with 26 queries.