Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

irpair.cpp

Committer:
sahilmgandhi
Date:
24 months ago
Revision:
29:ec2c5a69acd6
Parent:
15:b80555a4a8b9
Child:
32:69acb14778ea

File content as of revision 29:ec2c5a69acd6:

#include "irpair.h"
#include "mbed.h"

Ticker toggleIr;

void IRPair::calibrateSensor() {

    ir.write( 1 );
    wait_us(70);

    for (int i = 0; i < samplesToTake; ++i) 
        sensorAvg += recv.read();
        
    ir.write( 0 );
    sensorAvg /= samplesToTake;
}

float IRPair::getSamples( int samples )
{
    float z = 0;
    ir.write( 1 );
    wait_us(70);
    
    for( int i = 0; i < samples; ++i )
        z += recv.read();
    ir.write( 0 );
    return z / samples;
}