I'm creating a joystick program. I plug in the joystick, run the program, and numbers are printed out based on what buttons are being pressed on the joystick. This is going to be used for a robot.
However, I'm having a problem with it. I want the program to work so that I don't have to hold down the buttons when the numbers are being printed.
So if the 5th button on the joystick is pressed, the "Moving backwards" value is printed. However it only prints when I'm holding the button. I just want to press the button once, and then it prints when I'm not holding the button. Any ideas on how I can do this?Code://--- Run joystick session
running = true;
while (running) {
//--- Clear memory, load data structure
memset(&jixStick, 0x000, sizeof(JOYINFOEX));
jixStick.dwSize = sizeof(JOYINFOEX);
jixStick.dwFlags = JOY_RETURNALL;
joyGetPosEx(JOYSTICKID1, &jixStick);
numZpos = jixStick.dwZpos / 524;
numXpos = jixStick.dwXpos / 524;
//If none of the joystick buttons are pressed
if (!(jixStick.dwButtons & JOY_BUTTON5) && !(jixStick.dwButtons & JOY_BUTTON6) && !(jixStick.dwButtons & JOY_BUTTON4) && !(jixStick.dwButtons & JOY_BUTTON1)) {
cout << "The value of the Z position is: " << " " << numZpos << endl;
}
if ((jixStick.dwButtons & JOY_BUTTON5)) {
reverse = myArray[0] / 524;
cout << "Moving backwards..." << " " << reverse << endl;
}
}