I am trying to get the robot to switch a state based off the single press of a joystick button. I designed a system that i thought would work, but it began constantly switching the state back and forth without me pressing anything every (what I believe based off how i designed it) 10 ms.
I don't have the code with my right now, but in pseudo code this is what i did.
Code:
In periodic Tasks.vi
10 ms loop
If button pressed
if global button data == true
set global button data = false
if global button data == false
set global button data = true
In Teleop.vi
If global button data == true
set solenoid = forward
else
set solenoid = reverse
So basically, I have two case structures inside each other in the periodic tasks loop thats constantly checking for if the button is pressed, and I THINK I have the state changing when the button is pressed. I put it in the 10 ms loop because i didn't want it switching every cycle just because we held the button for more than a nanosecond, but i didn't want a WAIT slowing down our teleop. Anyway, the state is sent to the Global Robot Data and called in teleop, where a single case structure determines the solenoids.
If anyone can tell me why it did what it did, how to fix it, or another approach altogether, I would very much appreciate it.
I will post the real code ASAP.