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
Diff: SensorControl/lineSensor.h
- Revision:
- 1:813f4b17ae65
- Child:
- 3:01b5e80d842d
diff -r f45212966fb1 -r 813f4b17ae65 SensorControl/lineSensor.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SensorControl/lineSensor.h Sun Mar 03 00:54:07 2019 +0000
@@ -0,0 +1,59 @@
+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
+ }
+
+};
\ No newline at end of file