Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
SensorControl/lineSensor.h
- Committer:
- UditSrivastav
- Date:
- 2019-04-29
- Revision:
- 13:521d6c6e7042
- Parent:
- 9:cefa177c1353
File content as of revision 13:521d6c6e7042:
class lineSensor
{
private:
DigitalOut emitter;
AnalogIn receiver;
float static const vREF = 3.3f;
float lineVoltage;
Timeout sampler;
public:
float static const sampleTime = 0.00009f;
lineSensor(PinName E, PinName R):emitter(E), receiver(R)
{
sampler.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 sample(void)
{
turnOn();
lineVoltage = receiver.read()*vREF;
sampler.attach(callback(this, &lineSensor::turnOff),sampleTime);
}
float calcLineVoltage(void)
{
lineVoltage = receiver.read()*vREF;
return lineVoltage;
}
float returnLineVoltage(void)
{
return lineVoltage;
}
};