View Single Post
  #1   Spotlight this post!  
Unread 14-02-2015, 23:45
mshafer1 mshafer1 is offline
Programming Mentor
AKA: Matthew Shafer
FRC #3937 (Breakaway)
Team Role: Mentor
 
Join Date: Jan 2015
Rookie Year: 2008
Location: Arkansas
Posts: 58
mshafer1 is an unknown quantity at this point
Re: Counting up and down with a switch

Quote:
Originally Posted by GeeTwo View Post
If you want a switch that counts both up and down, you really need something like a quadrature encoder, or a gray code encoder. Either of these has at least two separate switches. The simplest quadrature encoder is for rotation, and has one switch "on" for angles between 0 and 180 degrees, "off" for 180 to 360. The other switch is rotated 90 degrees, so it will be "on" for 90 to 270 degrees, and "off" for 270 through 0 to 90 degrees. With this sort of setup, you can tell which way the wheel is rotating based on which switch is "leading" the other towards each state. If the first switch "leads", rotation is in the positive direction, if the second switch "leads", rotation is in the negative direction.

I'll leave gray code for you to google.
As GeeTwo stated, something more is really needed for what you are saying, it is possible to either put two switches, or the encoders that he suggested.
I am attaching a snippet that would count up and down as described, - note that it will go 1 or 0 always.
I am also attaching a snippet of what it could look like with the second switch.

I don't have access to LabVIEW for FRC right now, so I am posting a vi that could have the switch read wired into it. I have made it in the form of an FGV, but the point is just the memory of the last value should be used (through either shift register or feedback node)
Attached Thumbnails
Click image for larger version

Name:	counter_one.png
Views:	15
Size:	18.8 KB
ID:	18363  Click image for larger version

Name:	counter_two.png
Views:	11
Size:	22.7 KB
ID:	18364  
Reply With Quote