raskulous
Posts: 2
Joined: Wed Jul 21, 2021 12:38 am

Pi Pico as a rapid fire unit for an Arcade Stick

Wed Jul 21, 2021 1:01 am

Good afternoon,

I had some help with coding a rapid fire unit for use in an arcade stick that I'm building, and I'm hoping someone here would be able to help me fix a small bug.

It uses a "Turbo" button and a "Clear" button. You hold the Turbo button and press any of the 8 buttons to activate rapid fire, then do the same with the Clear button to return to a normal state.

The trouble is, Turbo and Clear will only work if you hold down one of the 8 buttons FIRST, then press Turbo or Clear.

If you hold Turbo, THEN one of the 8 buttons, rapid fire will not activate.

Would there happen to be anyone that would take a look at the code and find out why it will only work if the button is pressed before Turbo?

The code is here: https://codeshare.io/3AALYB

asu
Posts: 59
Joined: Sun Jul 18, 2021 8:19 am

Re: Pi Pico as a rapid fire unit for an Arcade Stick

Wed Jul 21, 2021 6:01 pm

I believe the problem lies in checkTurbo:

When the turbo button is pressed, you will enter the if block and assign lastT to T, even if you did not press any other button.
Meaning that the block will not get executed again until you release the turbo button and press it again.

EDIT: I recommend that you initialize your variables properly. When you do "bool p;", p is in an uninitialized state, so any read from this value is Undefined Behavior (UB) - meaning the compiler can generate code that *can* break under certain conditions (even though it doesn't seem to in your case). I recommend you get rid of this habit because it is bound to make you pull your hair at some point :)
(Technically - your static variables will be fine as static variables get initialized to 0, but it is always better to be explicit, and this has no performance penalty to it.)

raskulous
Posts: 2
Joined: Wed Jul 21, 2021 12:38 am

Re: Pi Pico as a rapid fire unit for an Arcade Stick

Sun Aug 01, 2021 4:59 am

asu wrote:
Wed Jul 21, 2021 6:01 pm
I believe the problem lies in checkTurbo
Thanks so much for your input. Unfortunately the person that coded this for me is unable to help me out any longer. Would you be willing to help me on this?

I don't have any coding experience, unfortunately.

Return to “General”