Hello there,
I'm working on a custom remote controller for a RC PowerWheels project. The remote is functioning as intended for the most part but I'm having trouble with a joystick push button and controlling a section of code with it.
The area where I'm having some trouble with is with the "Internal_Battery_Meas_State" variable that I declared. I've declared it as an int variable and set it to a LOW state. This is tied to a joystick push button which is read with a debounce timer. If the joystick button is pressed, then it pulls the input low and I've written code to then set the Internal_Battery_Meas_State to a HIGH state.
The problem I'm having is that the Internal_Battery_Meas_State is constantly going from a LOW state to a HIGH state and back. I'm not sure how it is being set to a HIGH state though and I'm trying to figure that out.
Using serial print I've confirmed that that if statement used to set it HIGH does not trigger and as such I'm unsure why this is happening. Looking forward to some help on this.
Refrences from where this variable is being called in the code:
Row 61: Declaring "Internal_Battery_Meas_State" as an integer and setting it to LOW
Row 396: Testing whether the If statement is satified and if so, then
Row 398: Setting the Internal_Battery_Meas_State to a HIGH state based on reading the joystick button press
Row 412: Setting the Internal_Battery_Meas_State to a LOW state to prevent potential clashing of variables
Row 423: Setting the Internal_Battery_Meas_State to a LOW state to prevent potential clashing of variables
Row 431: Setting the Internal_Battery_Meas_State to a LOW state to prevent potential clashing of variables
Row 567: Reading whether the Internal_Battery_Meas_State is HIGH, and if so, then execute the code int he if statement.
Row 849: Call a 5 second timer and once the 5 seconds have elapsed, then set the Internal_Battery_Meas_State low again after it was high. This function is called in the if statement when the Internal_Battery_Meas_State is read as high.
Row 913 - 920: Debugging function, reading the Internal_Battery_Meas_State and printing to the serial monitor whether it is high or low.
I've uploaded the code as well as a snapshot of the serial monitoring data. Thank you and looking forward to receiving some help to try and figure out what is happening here.

Custom_Remote_Control_Code.ino (32.5 KB)