![]() |
Button Programing
I have a relay programed to a button but now I want it to be a press to be forward and then press again to reverse. For example, I am using a selanoid and i want to press the button to have the cylinder go out then the next time i press it the cylinder go in. I can do this easilly in p-basic but I have tried to do it in C and I can't get it to work right. Could anyone give me a hand with this by posting code. It would be appreciated. Thanks
|
Re: Button Programing
Put something this in your user_routine, substituting appropriately for switch_value and relay_fwd/rev:
Code:
static char relay_state = 0; /* 0 means forward, 1 means reverse */ |
Re: Button Programing
Quote:
Code:
//... |
Re: Button Programing
Quote:
|
Re: Button Programing
We coded buttons/triggers to only activate on release, that helps control the longggggggggg button push :)
Phil |
Re: Button Programing
I would do this so your relays dont pulse 40x a second ;) I don't know whose code I just added to tho... sorry
int flag=0; //... //Init Relays relay1_fwd = 1; relay1_rev = 0; //... if (OI_Switch && !flag) { relay1_fwd = !relay1_fwd; relay1_rev = !relay1_rev; flag=1; } if (!OI_Switch) { flag=0; } |
Re: Button Programing
Quote:
[edit] My code (With suggestion): Code:
//... |
| All times are GMT -5. The time now is 16:47. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi