|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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....
|
|
#2
|
|||
|
|||
|
Re: using single solenoid like a double
Quote:
Last edited by SilverStar : 02-02-2004 at 21:15. Reason: misspelling and wrong words |
|
#3
|
|||
|
|||
|
Re: using single solenoid like a double
Quote:
|
|
#4
|
|||
|
|||
|
Re: using single solenoid like a double
Sure, the "toggle" code you need is at the repository:
http://nrg.chaosnet.org/repository/viewcode?id=23 |
|
#5
|
||||
|
||||
|
Re: using single solenoid like a double
if you mean you want to use two buttons like "on" and "off" buttons, here's one way to do it:
Code:
static char btn_status = 0; if(p1_sw_aux1) btn_status = 1; if(p1_sw_aux2) btn_status = 0; relay1_fwd = btn_status; |
|
#6
|
|||
|
|||
|
Re: using single solenoid like a double
Quote:
|
|
#7
|
||||
|
||||
|
Re: using single solenoid like a double
either way you want to work it.
|
|
#8
|
|||
|
|||
|
Re: using single solenoid like a double
Couldn't you do it with a simple XOR operation?
i.e. Code:
relay1_fwd ^= p1_sw_trig; |
|
#9
|
|||
|
|||
|
Re: using single solenoid like a double
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. |
|
#10
|
|||
|
|||
|
Re: using single solenoid like a double
Quote:
|
|
#11
|
|||
|
|||
|
Re: using single solenoid like a double
ahhh merci SilverStar, I was thinking of using something similar with even or odd number of times pressing the button, this works
|
|
#12
|
|||
|
|||
|
Re: using single solenoid like a double
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.
Code:
// 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;
|
|
#13
|
|||
|
|||
|
Quote:
|
|
#14
|
|||
|
|||
|
Re: using single solenoid like a double
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.
|
|
#15
|
||||
|
||||
|
Re: using single solenoid like a double
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. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Anyone willing to trade (something they need) for the SMC double solenoid? | Jeremy | Kit & Additional Hardware | 0 | 27-01-2004 20:14 |
| multiple cyclinders from one double solenoid | Ed Crammond | Pneumatics | 1 | 07-02-2003 18:49 |
| double solenoid | gail | OCCRA | 0 | 11-10-2002 19:42 |
| Will trade for double solenoid valve | archiver | 2001 | 2 | 24-06-2002 00:33 |
| Single Solenoid Valve SMC | Chubtoad | Technical Discussion | 3 | 20-01-2002 15:16 |