Go to Post This is the hint that never ends, yes it goes on and on my friend. Some people start guessing not knowing what it was, and they'll continue to guess forever just because... - JaneYoung [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 06-03-2009, 20:07
dboisvert dboisvert is offline
Registered User
AKA: Dan Boisvert
FRC #2405 (Divided by Zero)
Team Role: Programmer
 
Join Date: Feb 2009
Rookie Year: 2008
Location: Michigan
Posts: 57
dboisvert is an unknown quantity at this point
Joystick Button Press

I am trying to accomplish a simple button task. When someone pushes a button I want it to keep doing the action (IE In this case "Relay Forward" & "Relay Reverse") until the microswitch is activated. Right now it stops as soon as you release the button.


What the code looks like right now is this
Code:
if button1 == 1 & microswitch1 = 0
  Relay Forward
else if button2 == 1 & microswitch2 = 0
  Relay Reverse
else
  Relay Off
Any suggestions?
Reply With Quote
  #2   Spotlight this post!  
Unread 06-03-2009, 21:16
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: Joystick Button Press

Quote:
Originally Posted by dboisvert View Post
I am trying to accomplish a simple button task. When someone pushes a button I want it to keep doing the action (IE In this case "Relay Forward" & "Relay Reverse") until the microswitch is activated. Right now it stops as soon as you release the button.


What the code looks like right now is this
Code:
if button1 == 1 & microswitch1 = 0
  Relay Forward
else if button2 == 1 & microswitch2 = 0
  Relay Reverse
else
  Relay Off
Any suggestions?
int dir=0;//at the top
...
loop//your while loop
..
if (button1 ==1 && !(microswitch1==1))//if button1 pressed and microsw ! pressed
dir=1;
else if (button2==1 && !(microswitch2==1))//if button2 pressed and microsw ! pressed
dir=-1;
else if (microswitch1 ==1 || microswitch2 ==1)//if microsw pressed
dir=0;
//otherwise do nothing to the value
relay.Set((float)dir);//set the new (or old )value
...
end loop
...
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
Reply With Quote
  #3   Spotlight this post!  
Unread 06-03-2009, 21:21
The Lucas's Avatar
The Lucas The Lucas is offline
CaMOElot, it is a silly place
AKA: My First Name is really "The" (or Brian)
FRC #0365 (The Miracle Workerz); FRC#1495 (AGR); FRC#4342 (Demon)
Team Role: Mentor
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Dela-Where?
Posts: 1,564
The Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond repute
Send a message via AIM to The Lucas
Re: Joystick Button Press

Quote:
Originally Posted by dboisvert View Post
I am trying to accomplish a simple button task. When someone pushes a button I want it to keep doing the action (IE In this case "Relay Forward" & "Relay Reverse") until the microswitch is activated. Right now it stops as soon as you release the button.


What the code looks like right now is this
Code:
if button1 == 1 & microswitch1 = 0
  Relay Forward
else if button2 == 1 & microswitch2 = 0
  Relay Reverse
else
  Relay Off
Any suggestions?
Try this:
Code:
if (button1 == 1 && microswitch1 == 0)
  Relay Forward
else if (button2 == 1 && microswitch2 == 0)
  Relay Reverse
else (0 == microswitch1 || 0 == microswitch2)
  Relay Off
= is the assignment operator and "microswitch = 0" sets microswitch to the value of 0 is always is true. You need to use == which is conditional equals

It is a best practice to write the statement 0 == microswitch so the compiler can catch the mistake (0=microswitch is an error)

Also it is better to use a logial and (&&) rather than a bitwise and (&) since the bitwise and will not work in all situations (2 & 1 =false)
__________________
Electrical & Programming Mentor ---Team #365 "The Miracle Workerz"
Programming Mentor ---Team #4342 "Demon Robotics"
Founding Mentor --- Team #1495 Avon Grove High School
2007 CMP Chairman's Award - Thanks to all MOE members (and others) past and present who made it a reality.
Robot Inspector
"I don't think I'm ever more ''aware'' than I am right after I burn my thumb with a soldering iron"

Last edited by The Lucas : 06-03-2009 at 21:30. Reason: I didnt notice he wanted latching
Reply With Quote
  #4   Spotlight this post!  
Unread 06-03-2009, 22:20
dboisvert dboisvert is offline
Registered User
AKA: Dan Boisvert
FRC #2405 (Divided by Zero)
Team Role: Programmer
 
Join Date: Feb 2009
Rookie Year: 2008
Location: Michigan
Posts: 57
dboisvert is an unknown quantity at this point
Re: Joystick Button Press

Im aware of the proper syntax but I probably should have said it was more of a "Pseudo-Code"
Reply With Quote
  #5   Spotlight this post!  
Unread 06-03-2009, 23:30
dboisvert dboisvert is offline
Registered User
AKA: Dan Boisvert
FRC #2405 (Divided by Zero)
Team Role: Programmer
 
Join Date: Feb 2009
Rookie Year: 2008
Location: Michigan
Posts: 57
dboisvert is an unknown quantity at this point
Re: Joystick Button Press

Code:
flipperdoor->Set(Relay::flipperset);
I get an error that says "flipperset is not a member of Relay"
Reply With Quote
  #6   Spotlight this post!  
Unread 07-03-2009, 04:15
The Lucas's Avatar
The Lucas The Lucas is offline
CaMOElot, it is a silly place
AKA: My First Name is really "The" (or Brian)
FRC #0365 (The Miracle Workerz); FRC#1495 (AGR); FRC#4342 (Demon)
Team Role: Mentor
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Dela-Where?
Posts: 1,564
The Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond repute
Send a message via AIM to The Lucas
Re: Joystick Button Press

Quote:
Originally Posted by dboisvert View Post
Code:
flipperdoor->Set(Relay::flipperset);
I get an error that says "flipperset is not a member of Relay"
You have to use

Code:
flipperdoor->Set(Relay::kForward);
OR
Code:
flipperdoor->Set(Relay::kReverse);
OR
Code:
flipperdoor->Set(Relay::kOff);
__________________
Electrical & Programming Mentor ---Team #365 "The Miracle Workerz"
Programming Mentor ---Team #4342 "Demon Robotics"
Founding Mentor --- Team #1495 Avon Grove High School
2007 CMP Chairman's Award - Thanks to all MOE members (and others) past and present who made it a reality.
Robot Inspector
"I don't think I'm ever more ''aware'' than I am right after I burn my thumb with a soldering iron"
Reply With Quote
  #7   Spotlight this post!  
Unread 07-03-2009, 11:09
dboisvert dboisvert is offline
Registered User
AKA: Dan Boisvert
FRC #2405 (Divided by Zero)
Team Role: Programmer
 
Join Date: Feb 2009
Rookie Year: 2008
Location: Michigan
Posts: 57
dboisvert is an unknown quantity at this point
Re: Joystick Button Press

What I believe I am trying to accomplish is setting it outside of the loop. So basically store a variable and set it to that variable later.

Initial Decleration of flipperset (unsure if that will work)

Code:
Relay::Value flipperset;
sets flipperset to shut the relay off
Code:
		flipperset = Relay::kOff;
If statements to change the flipperset variable
Code:
			if (m_leftStick->GetRawButton(5) == 1 && flipperdoorright->Get() == 0 ) {
				flipperset = Relay::kForward;
			} else if (m_leftStick->GetRawButton(4) == 1 && flipperdoorleft->Get() == 0 ){
				flipperset = Relay::kReverse;
			} else if (flipperdoorleft->Get() == 1 || flipperdoorright->Get() == 1) {
				flipperset = Relay::kOff;
			}
Final set of flipperdoor to a certain variable
Code:
flipperdoor->Set(flipperset);
Reply With Quote
Reply


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
joystick button furiousgeorge Programming 5 07-02-2009 15:57
Intelitek Loader Press PRGM Button Fail ttldomination VEX 1 25-02-2008 19:36
Joystick Hat button ten3brousone Programming 8 20-02-2005 13:31
Joystick Button Deference cibressus53 Electrical 3 01-11-2004 09:38
Can a student Coach press the Stop Button archiver 2001 3 24-06-2002 02:39


All times are GMT -5. The time now is 13:55.

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