.Counts( )

back to DigitalEncoder

Description

This member function can be used to obtain the current counts for the associated DigitalEncoder object.

P3_6 and P3_7 cannot be used for digital encoders!!

Parameters

None.

Returns

This function returns the current counts for a DigitalEncoder object as an integer.

Examples

#include <FEHIO.h>
#include <FEHMotor.h>

int main(void)
{
    //declares a digital encoder on P0_3
    DigitalEncoder right_encoder(FEHIO::P0_3);

    //declares a motor on motor port 0
    FEHMotor right_motor(FEHMotor::Motor0);

    //turn on the right motor to 75% power
    right_motor.SetPercent( 75.0 );

    //ensure that the encoder counts are at zero by resetting 
    right_encoder.ResetCounts();

    //wait until the right encoder reaches 500 counts
    while(right_encoder.Counts() < 500);

    //stop the motor
    right_motor.Stop();
}