I've been working a small modification to a little button panel for video games. It was working fine, and then I decided to add a switch and a couple buttons. Somehow, being the genius I am, I couldn't find the code I had been using to just modify, so I started fresh.
All the buttons before were working with the previous code. With the new code however, when I press a button it sticks on. I've been going over it for a few hours now, and I have a little bit of the code I had been using, and that works fine. Something about this new code, which as far as I can tell, except for different names, is the same code, just won't work. It just keeps being read as on. And I know my code is probably kinda terrible, but it works alright for me. Well... so I thought.
Here's the working code:
#include "Joystick.h"
Joystick_ Joystick;
const int AH = 7; //3
void setup() {
// put your setup code here, to run once:
pinMode(AH, INPUT_PULLUP);
Joystick.begin();
}
int LBAH = 0;
void loop() {
// put your main code here, to run repeatedly:
int currentButtonStateAH = !digitalRead(AH); //3
if (currentButtonStateAH != LBAH)
{
Joystick.setButton(2, currentButtonStateAH);
LBAH = currentButtonStateAH;
}
}
And here's the non-working code:
#include "Joystick.h"
Joystick_ Joystick;
const int But1 = 7; //3
void setup() {
// put your setup code here, to run once:
pinMode(But1, INPUT_PULLUP);
Joystick.begin();
}
int LBBut1 = 0;
void loop() {
// put your main code here, to run repeatedly:
int currentButtonState = !digitalRead(But1); //3
if (currentButtonState != LBBut1)
{
Joystick.setButton(2, But1);
LBBut1 = currentButtonState;
}
}