View Single Post
  #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