Go to Post All I wanted was a game hint.... :( - JohnBoucher [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

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 18-02-2008, 10:01
Ghandric's Avatar
Ghandric Ghandric is offline
Mike
AKA: Michael Kober
FRC #2668
Team Role: Programmer
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Lansdale, Pennsylvania
Posts: 6
Ghandric is an unknown quantity at this point
Send a message via MSN to Ghandric Send a message via Yahoo to Ghandric
Exclamation Getting a button to latch its value until it is pressed again

Alright... when I press a button I need it to hold a value of 1 even if it is released. Then... when it is pressed again I need it to return its value to 0. To anyone who responds to this post you have all of my respect and thanks. Just to say it again to make sure I don't screw up in saying it... when I press a button I need it to hold a value of one even after it has been released. Then when i press it again i need it to return its value to 0. Thanks again.
  #2   Spotlight this post!  
Unread 18-02-2008, 10:09
psy_wombats's Avatar
psy_wombats psy_wombats is offline
Registered User
AKA: A. King
FRC #0467 (Duct Tape Bandits)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Shrewsbury MA
Posts: 95
psy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura about
Re: Getting a button to latch its value until it is pressed again

This involves storing the last state of your button, something like this:

Code:
void Run_Motor_Button (void)
static unsigned char engage_motor = 0; //Should the motor be on?
static unsigned char last_button_state = 0; //This will be the last position of p3_sw_trig
if (p3_sw_trig && !last_button_state){ //The button is pushed but wasn't last time
engage_motor = !engage_motor //Change what should be happening to the motor
}
last_button_state = p3_sw_trig; //Update the state of the button
if (engage_motor){ //Use the motor if needed
pwm02 = 255;
} else {
pwm02 = 127;
}
This is a good thing to know how to do, as it is used fairly often. I advise that instead of copy/pasting the code that you read the comments and write a similar routine yourself.
  #3   Spotlight this post!  
Unread 18-02-2008, 12:08
ay2b's Avatar
ay2b ay2b is offline
Registered User
AKA: Andy
FRC #2928
Team Role: Mentor
 
Join Date: Mar 2004
Rookie Year: 1994
Location: Seattle, WA
Posts: 211
ay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant future
Re: Getting a button to latch its value until it is pressed again

Depending on your usage, another option may be to by a pushbutton switch. Search for anything that's either "spst pushbutton" or "spdt pushbutton", but not "momentary". Here are two options from RadioShack: http://www.radioshack.com/product/in...ductId=2062510
http://www.radioshack.com/product/in...ductId=2062544
__________________

2011 - SD Quarterfinalists (980), LA Quarterfinalists (980)
2010 - LA (2404) Finalists (980), AZ Motorola Quality (980)
2009 - LA Semifinalists (980); Las Vegas Quarterfinalists (980); SD (2404); IRI #1 Seed, Finalist (980)
2008 - SD Quarterfinalists (980), LA Champions (980), LA Rookie Inspiration Award (2404); CalGames Finalists
2007 - So.Cal Finalists (980), SD Quarterfinalists (980); CalGames Finalists
2006 - So.Cal Regional Champion (4), Toronto Judge's Award Day 1 (4)
2005 - SVR Champions, Delphi "Driving Tomorrow's Technology" (980); AZ Xerox Creativity (980); So.Cal Finalists, RadioShack Innovation in Control (980); Championship Archimedes Division Semifinalists; IRI Finalists (980)
2004 - So.Cal Regional Champions, Leadership in Controls (980); AZ GM Industrial Design (980); Championship Galileo Division #2 Seed; IRI Champions
2003 - PNW Semi-finalists (488)
2002 - PNW Finalists (488)
2000 - X-bot / 488 - Mentor / Founder
1994 - Sunny Delight - Driver - champion
Closed Thread


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
Its getting to be RIDICULOUS! Marygrace General Forum 42 15-01-2008 17:35
7 Days Until We DUEL !!! Mr MOE Off-Season Events 38 21-10-2006 19:42
Countdown Until Ship sanddrag General Forum 3 13-02-2003 08:51
Do ... Until ... Loop Goya Programming 5 19-01-2003 09:52


All times are GMT -5. The time now is 12:07.

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