Coding an ignition switch

I can't log in to see a video. And any reasoning I do here is with total ignorance of the joystick library.

But it seems that what you need to do is make a button look like it gets pressed, then released, when your ignition OFF part contacts open up.

So I think your code is doing what you think, but not what needs to be done.

The '1' circle is the indicator for a pushbutton. It would be on when the button is pressed, and off when not pressed.

This is pure, or rank, speculation, so I hope some joystick/button box heavies are following along, but I think this is what you need to do to fake a button press:

    if (buttonState1 == HIGH) {  // **turn the IGN on**
           Joystick.setButton(0, 1);  // "press" button 0

// delay needed here? I hope not, but it will otherwise appear as a very short stab

           Joystick.setButton(0, 0);  // "release" button 0
    } 

As you turn the ignition switch from 0 to 1 to 2 to 1 to 0, there are four fully detectable state transitions. Any of them that needs to be turned into a faked button press can just execute code that presses, then releases an appropriate "pushbutton".

A similar problem on these fora from some time ago was how to turn a toggle switch into an on/off pushbutton signal, and something like this was the solution. I'll try to find it.

Now that raised an interesting problem, as the code has no way of knowing the state of the game. So it has to assume that when it starts, it can be assured that the engine in the game is off.

Kinda like how your TV goes off or on when you hit the power button. If you've ever gotten two things meant to obey that one power change command where one is off, and one is on, you see the problem. Toggling the power just turns one on and the other off, there is no "turn on" command, only a toggle.

OK, this post the entire thread, and a linked thread


HTH

Oh, there's a link to a simulation I wrote that is broken, it may be that I deleted a project not realizing it was supposed to last forever...

a7