need help coding a switch on arduino for flight sim
1 hour ago, AnotherMax said:If it just spams a bunch that implies the switches you are using might already be toggle switches as oppose to buttons?
I don't think what minibois said would help as delaying going into the `doAction(i)` function won't change the actual delay between when the button is pressed and released.
I didn't really read/understand the full code, but just saw the debounce mentioned in the code.
The idea behind debouncing is that when you press a button, it's possible a very stable connection isn't made that very instant. Debounce basically looks at the first time a button was pressed and waits a little bit, to make sure the button press is 'legit' and not just a fluke.
That may not be the fix for sure though.
39 minutes ago, SkippyDing said:ill have a little look at that now, thanks!
I just realized the problem is probably that every 'frame' the Arduino looks at the pins again to see which button(s) are pressed and based on your code it just goes "button x is press > press keycode y on the PC".
The problem with this, is that basically every 'frame' the Arduino goes "press keycode y!"
As you can see in the code, the button gets released each 'frame' too:
Keyboard.press('1'); delay(10); Keyboard.releaseAll();
You'd need to make it so the button is held down, until you don't hold it down anymore.
So instead of just scanning for "is button pressed down", you need to scan for:
- Is button held down
- If not held down, release
That is what I think is going wrong. You're telling the Arduino each frame "press the button, now unpress it".
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now