View Single Post
  #2   Spotlight this post!  
Unread 22-03-2004, 07:05
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: counting digital input

Either use polling, meaning you check for a change in state of the digital input every loop, or use interrupts. As you don't have much time, I would recommend the polling, as it can be done easily with no bugs.

For the polling you would have something like this:
Code:
// This is the output that anyone can read. Rename it to something better and more descriptive
int ticks = 0;

void checkDigitalIn(void)
{
    // This is used to tell us when we change states
    static char lastState = 0;

    // This does the actual checking. Make the dig_in_01 whatever input you are working with.
    if(lastState != dig_in_01)
    {
         ticks++;
         // This marks the lastState as the opposite of itself, meaning it now equals the digital input
         lastState = !lastState;
    }
}
That's all there is to it. Just call that as often as you can in your and when it sees the input cange from high to low or low to high, it will increment the global variable.

--EDIT--
If you want it to only catch one type of state change (IE low to high), then have it check if it has reached the state you want it to before it increments.
__________________