Buggy bois / Mbed 2 deprecated headache

Dependencies:   mbed

SensorControl/lineSensor.h

Committer:
mazdo25
Date:
2019-03-03
Revision:
1:813f4b17ae65
Child:
3:01b5e80d842d

File content as of revision 1:813f4b17ae65:

class lineSensor
{
    
    private:
    DigitalOut emitter;
    AnalogIn receiver;
    float static const vREF = 3.3f;
    Timeout sampleTime;
    float lineVoltage;
    
    public:
    
    lineSensor(PinName E, PinName R):emitter(E), receiver(R)
    {   
       sampleTime.detach();
    }
    
    //Turn on the emitter i.e emit a light
    void turnOn(void)
    {
        emitter.write(1);   
    }
    
    //turn off the emitter i.e don't emit a light
    void turnOff(void)
    {
        emitter.write(0);
    }
    
    //toggle the emitter i.e if its on turn it off, if its off turn it on
    void toggleEmitter(void)
    {
        emitter.write(!emitter.read());
    }
    
    //return an int representing the state of the emitter i.e is it on or off where 1 represents on and 0 represents off
    int returnEmitterState(void)
    {
        return emitter.read();
    }
    
    void calcLineVoltage(void)
    {
        lineVoltage = receiver.read() * vREF;
        turnOff();
    }
    
    float returnLineVoltage(void)
    {
     return lineVoltage;
    }
    
    void takeReading()
    {
        turnOn();
        sampleTime.attach(callback(this, &lineSensor::calcLineVoltage),0.09); //time till turn off
    }
    
};