View Full Version : using single solenoid like a double
We're wondering if it is possible to use a single solenoid like a double basically by having to only press a button once instead of holding it down. Tell me if I'm crazy about the solenoid thing, but it seems possible to edit the program so that pressing the thumb or trigger on a joytick (pX_sw_whatever) once will keep the relay attached to its corresponding relay output in forward mode. How would you go about doing this? I think I have an idea, but I am a n00b and don't wanna embarass myself....
We're wondering if it is possible to use a single solenoid like a double basically by having to only press a button once instead of holding it down. Tell me if I'm crazy about the solenoid thing, but it seems possible to edit the program so that pressing the thumb or trigger on a joytick (pX_sw_whatever) once will keep the relay attached to its corresponding relay output in forward mode. The double-solenoid valve works by outputting air into one side of the piston to make it extend. You then set it in reverse (the spike) to put air into the other side of the piston to make it retract. You can't model a double-solenoid using a single-solenoid by changing the software. The purpose of a double-solenoid valve is to be able to actuate the piston in both directions, ONE single solenoid valve cannot do this, but TWO SINGLE solenoid valves can
The double-solenoid valve works by outputting air into one side of the piston to make it extract. You then set it in reverse (the spike) to put air into the other side of the piston to make it extract. You can't model a double-solenoid using a single-solenoid by changing the software. The purpose of a double-solenoid valve is to be able to actuate the piston in both directions, ONE single solenoid valve cannot do this, but TWO SINGLE solenoid valves can
Ok so I am indeed crazy about the solenoid thing, but can anyone help me out with a way to keep the relay forward while only pressing the button once instead of holding it down?
Sure, the "toggle" code you need is at the repository:
http://nrg.chaosnet.org/repository/viewcode?id=23
deltacoder1020
02-02-2004, 21:15
if you mean you want to use two buttons like "on" and "off" buttons, here's one way to do it:
static char btn_status = 0;
if(p1_sw_aux1) btn_status = 1;
if(p1_sw_aux2) btn_status = 0;
relay1_fwd = btn_status;
basically, just declare a static variable (so that it holds its state), then use the input from the buttons to set the variable at the appropriate times. (note - some of the input variable names may be off, i'm doing this from memory only)
if you mean you want to use two buttons like "on" and "off" buttons, here's one way to do it:
static char btn_status = 0;
if(p1_sw_aux1) btn_status = 1;
if(p1_sw_aux2) btn_status = 0;
relay1_fwd = btn_status;
basically, just declare a static variable (so that it holds its state), then use the input from the buttons to set the variable at the appropriate times. (note - some of the input variable names may be off, i'm doing this from memory only)
The code needs to be made slightly more complex because, as I interpret it, SteveO wants one button to toggle, my code above solves that.
deltacoder1020
02-02-2004, 21:21
either way you want to work it.
velocipenguin
02-02-2004, 21:33
Couldn't you do it with a simple XOR operation?
i.e. relay1_fwd ^= p1_sw_trig;
No, because the p1_sw_trig will remain true for more than one frame (unless your driver moves faster than light :) ). Thus, relay1_fwd would continuously switch from 0 to 1.
velocipenguin
02-02-2004, 21:57
No, because the p1_sw_trig will remain true for more than one frame (unless your driver moves faster than light :) ). Thus, relay1_fwd would continuously switch from 0 to 1.
Good point.
ahhh merci SilverStar, I was thinking of using something similar with even or odd number of times pressing the button, this works
velocipenguin
02-02-2004, 22:10
If you do it this way, it should only toggle the relay output when the button transitions from one state to another. That should eliminate the problem of infinite toggling that was present in my last suggestion.
// declare this as a global variable
bool LastButtonValue=0;
// place the following within the main loop
if(p1_sw_trig!=LastButtonValue)
relay1_fwd ^= p1_sw_trig;
LastButtonValue = p1_sw_trig;
If you do it this way, it should only toggle the relay output when the button transitions from one state to another. That should eliminate the problem of infinite toggling that was present in my last suggestion.
// declare this as a global variable
bool LastButtonValue=0;
// place the following within the main loop
if(p1_sw_trig!=LastButtonValue)
relay1_fwd ^= p1_sw_trig;
LastButtonValue = p1_sw_trig;
umm... that's exactly what's in the repository link above .....
velocipenguin
02-02-2004, 22:49
It's a little more concise, but yeah, you're right. I shouldn't attempt to think when I haven't slept much - this is what happens. Sorry.
deltacoder1020
02-02-2004, 22:51
nothing really to be sorry about - posting the code here doesn't hurt.
also, instead of a global variable, i'd recommend a static - that way, you don't have any possible variable conflicts.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.