View Single Post
  #4   Spotlight this post!  
Unread 15-02-2015, 14:35
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 Zaque View Post
Not to be rude, but this is the Java sub-forum, so some who do not have experience with LabVIEW may not be able to make heads or tails of the code you posted. If I get time I may be able to translate what you posted into Java pseudocode though .
Thanks for pointing that out, Zaque. I guess I got a little ahead of myself. This is still a generic counter utility based on edges of a boolean input that could come from a DIO read, but I am sure there are other ways (like the one posted by jhersh)
To accomplish an equivalent of what I posted in Java, it would require static variables. i.e.

class Counter
{
private static boolean LastUpCount;
private static boolean LastDownCount;
private static int count;
public static int counter(boolean upCounter, boolean downCounter)
{
if(upCounter && !LastUpCount)
{
count++;
}
if(downCounter && !LastDownCount)
{
count--;
}
LastDownCount = downCounter;
LastUpCount = upCounter;
return count;
}
};

Last edited by mshafer1 : 15-02-2015 at 14:37. Reason: clarify
Reply With Quote