counter.h

Committer:
daveTshave
Date:
2011-11-25
Revision:
3:bd08a59ee473
Parent:
2:fa04a99dcdab

File content as of revision 3:bd08a59ee473:

#ifndef counter_H
#define counter_H

/**
 * Includes
 */
#include "mbed.h"

/**
 * Simple counter
 */
class counter {

public:

    
    /**
     * Constructor.
     *
     * Attaches the encode function to the rise edge of
     * channel A.
     *
     * @param channelA mbed pin for counter input.
     */
    counter(PinName channelA);

    /**
     * Reset the encoder.
     *
     * Sets the pulses to zero.
     */
    void reset(void);

    /**
     * Read the number of pulses recorded by the encoder.
     *
     * @return Number of pulses which have occured.
     */
    int getPulses(void);

private:

    /**
     * Update the pulse count.
     *
     * Called on every rising edge of channels A.
     *
     */
    void encode(void);

    InterruptIn channelA_;
    
    volatile int pulses_;
    
};

#endif /* counter_H */