Hello,
I have a project which has a mixture of 10 buttons and toggles, and 2 rotary encoders. The idea is that all of them will send joystick button presses.
Some toggles will be on/off like a button, but some will send a momentary joybutton push when toggled. The rotary encoders will send a momentary joybutton push when they increment/decrement.
In isolation everything is good. The rotary encoders are interrupt driven and the loop() queries their value for changes, and the other buttons/toggles are debounced and updated.
But putting it all together it looks a little ugly. Every loop() I check the values of the rotary encoders for changes, then "if rising/falling edge" all 10 buttons and joybutton them if active. It's a massive long list of if's.
1) Is that an ok way to operate? I don't have a good measure for the time it takes to go through that loop. Should I check all of the control positions then do the joystick update in one update?
2) To do the momentary joystick button presses when the rotary encoder ticks, or a toggle toggles I do:
But that adds a 50ms block every time this activates. Is that a problem? I'm not making a fighting game controller, this is a flight sim control panel, so super speed is not an issue.
Basically, is this a perfectly fine way to do a controller or am I unaware of a much preferable paradigm?
I have a project which has a mixture of 10 buttons and toggles, and 2 rotary encoders. The idea is that all of them will send joystick button presses.
Some toggles will be on/off like a button, but some will send a momentary joybutton push when toggled. The rotary encoders will send a momentary joybutton push when they increment/decrement.
In isolation everything is good. The rotary encoders are interrupt driven and the loop() queries their value for changes, and the other buttons/toggles are debounced and updated.
But putting it all together it looks a little ugly. Every loop() I check the values of the rotary encoders for changes, then "if rising/falling edge" all 10 buttons and joybutton them if active. It's a massive long list of if's.
1) Is that an ok way to operate? I don't have a good measure for the time it takes to go through that loop. Should I check all of the control positions then do the joystick update in one update?
2) To do the momentary joystick button presses when the rotary encoder ticks, or a toggle toggles I do:
Code:
Joystick.button(13, 1);
delay(50);
Joystick.button(13, 0);
Basically, is this a perfectly fine way to do a controller or am I unaware of a much preferable paradigm?