|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#10
|
||||
|
||||
|
Re: Single Click On/Off Using the Trigger in EasyC
This is how we do it, although we have since developed and function call method that is a little more sophisticated than this sample. But this sample does work.
static unsigned char p1_sw_trig_prev = 0; if ((p1_sw_trig == 1) && (p1_sw_trig_prev == 0)) relay1_fwd = !relay1_fwd; p1_sw_trig_prev = p1_sw_trig; So what is all of this and what does it mean... 1) We define a static variable to hold the contents of the state of the button to be compared with on the next pass through the program loop. 2) We say if the trigger is being pressed and was previously in a released state then change the state of relay1_fwd. But if not don't do anything. 3) The relay1_fwd = !relay1_fwd statement causes relay1_fwd to change states. If relay1_fwd initially was zero, it becomes 1 and vice versa. 4) We then save the state of the trigger in our static variable to use in the comparison next time through. What will happen now is every time you pull the trigger and release it will case the relay1_fwd to toggle between on and off. What you are accomplishing here is making your trigger into a toggle switch of sorts. Click once it's on, Click again it's off, click again it's on, click again it's off and so on.... I hope this helps you to understand better what is happening. Last edited by Phalanx : 31-05-2007 at 09:13. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| multiple autonomous modes using easyc | cerberus170 | Programming | 3 | 20-02-2007 15:01 |
| Using printf() as UserCode in EasyC 2.0 | tacman1123 | Programming | 2 | 31-05-2006 10:01 |
| Using SMC Single Selenoid Valve from last year? | Sachiel7 | Pneumatics | 3 | 20-01-2005 21:31 |
| Is Anyone Using Motors to Hoist themselves off the platform on the bar? | xxlshortys | Motors | 36 | 25-02-2004 01:06 |
| using single solenoid like a double | SteveO | Programming | 14 | 02-02-2004 22:51 |