Go to Post I had a fight with my robot once during competition. I felt bad about it and apologized. - Tommy F. [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Spotlight this post!  
Unread 31-05-2007, 09:11
Phalanx's Avatar
Phalanx Phalanx is offline
Formerly Team 1089 (Mercury)
AKA: Michael Reffler
FRC #5431 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jun 2005
Rookie Year: 1999
Location: Lewisville, TX (previously NJ)
Posts: 384
Phalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond reputePhalanx has a reputation beyond repute
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.
__________________
Don't just ask the experts, become one!
Leadership is not about ability. It's about responsibility!
Diagonally Parked in a Parallel Universe. It's okay we do Quantum Physics



Last edited by Phalanx : 31-05-2007 at 09:13.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 11:52.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi