back to AnalogEncoder
Description
This function is required to define the low and high thresholds for an AnalogEncoder object. The AnalogEncoder object will increment its counts variable once a complete transition from below the low threshold to above the high threshold occurs, or once a complete transition from above the high threshold to below the low threshold occurs. Therefore, it is recommended that you provide some tolerance between the true low and high values for your encoder and the low and high threshold values. For example, if your encoder reads 0.1 on a white surface and 2.65 on a dark surface, a reasonable low threshold value would be 0.2 and a reasonable high threshold value would be 2.55.
Parameters
This function requires two floating point values:
Input 1: low threshold value
Input 2: high threshold value
Returns
None.
Examples
#include <FEHIO.h> #include <FEHMotor.h> #define LOW_THRESH 0.15 #define HIGH_THRESH 2.20 int main(void) { //declares an analog encoder on P0_3 AnalogEncoder right_encoder(FEHIO::P0_3); //set the analog encoder threshold right_encoder.SetThresholds( LOW_THRESH, HIGH_THRESH ); //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(); }