View Full Version : Getting the relays to stay constant
Lord Nerdlinger
19-02-2004, 06:19
Right now we have our pump hooked up to one of the spikes on #5 and while it works (press a button and it goes on) it doesn't stay on and it's really annoying to have to hold it down.
I think* (i don't know how to code and no one on the team does) that all I have to do is something like this
when joystick button is depressed set a variable equal to one
then do an if statement, if variable equals 1 to set the relay to fwd, else if, set relay to neutral position i guess fwd and rev are equal to zero?
I don't know the proper syntax or way about doing this, but i think it would only be a 1 or 2 lines of code
could anyone tell me how to do it or write it out so I could just copy and paste it into our code? plzzzz
It's #5 if you want to write it out
Do something like this:
unsigned char state = 0;
unsinged char switchState = 0;
// Check switches. Substitute switch for whatever switch on the OI you are using
// I use the switch state to prevent the switching of the state do to not realeasing the button right away
if(switch && !switchState)
{
// Set switch state
swtichState = 1;
// Switch states
if(switch)
state = 0;
else
state = 1;
}
else if(!switch)
{
// reset the switch state
switchState = 0;
}
// Subitute relay with your relay
if(state)
{
// Run forward
relay_fwd = 1;
relay_rev = 0;
}
else
{
// Turn off relay
relay_fwd = 0;
relay_rev = 0;
}
Put that whole thing where ever you are doing your cheking currently. Put the varable declarations at the top of whatever function you have this in. That should work. (I hope... ;))
Right now we have our pump hooked up to one of the spikes on #5 and while it works (press a button and it goes on) it doesn't stay on and it's really annoying to have to hold it down.
I think* (i don't know how to code and no one on the team does) that all I have to do is something like this
when joystick button is depressed set a variable equal to one
then do an if statement, if variable equals 1 to set the relay to fwd, else if, set relay to neutral position i guess fwd and rev are equal to zero?
I don't know the proper syntax or way about doing this, but i think it would only be a 1 or 2 lines of code
could anyone tell me how to do it or write it out so I could just copy and paste it into our code? plzzzz
It's #5 if you want to write it out
This isn't what you're looking for, but you may like this, use it, and even learn from it. In the default code, if you hook up the compressor to relay 8, and hook up your preassure switch( that came with your kit ) to digital in 18, whenever the preasure is below 95, it will pump untill it gets to 115 (or somewhere around there). What happens is this:
relay8rev = !digitalinput18;
those names area ll wrong because I dont have code with me, but what it does is set the relay to the opposite value of the digital input sensor (in this case, the preasure switch). If the swith is 1 (it's up to preasure) the relay is off. If it's below presure (0), then the relay will fire up (to 1). Hope you can learn something from this.
~Bstempi
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.