Buggy bois / Mbed 2 deprecated headache

Dependencies:   mbed

Committer:
UditSrivastav
Date:
Mon Apr 29 09:40:30 2019 +0000
Revision:
13:521d6c6e7042
Parent:
9:cefa177c1353
Anythign um

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mazdo25 1:813f4b17ae65 1 class lineSensor
mazdo25 1:813f4b17ae65 2 {
mazdo25 1:813f4b17ae65 3 private:
mazdo25 3:01b5e80d842d 4
mazdo25 1:813f4b17ae65 5 DigitalOut emitter;
mazdo25 1:813f4b17ae65 6 AnalogIn receiver;
mazdo25 1:813f4b17ae65 7 float static const vREF = 3.3f;
mazdo25 1:813f4b17ae65 8 float lineVoltage;
mazdo25 3:01b5e80d842d 9 Timeout sampler;
mazdo25 1:813f4b17ae65 10
mazdo25 1:813f4b17ae65 11 public:
UditSrivastav 13:521d6c6e7042 12 float static const sampleTime = 0.00009f;
mazdo25 1:813f4b17ae65 13
mazdo25 1:813f4b17ae65 14 lineSensor(PinName E, PinName R):emitter(E), receiver(R)
mazdo25 1:813f4b17ae65 15 {
mazdo25 3:01b5e80d842d 16 sampler.detach();
mazdo25 3:01b5e80d842d 17 }
mazdo25 1:813f4b17ae65 18
mazdo25 1:813f4b17ae65 19 //Turn on the emitter i.e emit a light
mazdo25 1:813f4b17ae65 20 void turnOn(void)
mazdo25 1:813f4b17ae65 21 {
mazdo25 1:813f4b17ae65 22 emitter.write(1);
mazdo25 1:813f4b17ae65 23 }
mazdo25 1:813f4b17ae65 24
mazdo25 1:813f4b17ae65 25 //turn off the emitter i.e don't emit a light
mazdo25 1:813f4b17ae65 26 void turnOff(void)
mazdo25 1:813f4b17ae65 27 {
mazdo25 1:813f4b17ae65 28 emitter.write(0);
mazdo25 1:813f4b17ae65 29 }
mazdo25 1:813f4b17ae65 30
mazdo25 1:813f4b17ae65 31 //toggle the emitter i.e if its on turn it off, if its off turn it on
mazdo25 1:813f4b17ae65 32 void toggleEmitter(void)
mazdo25 1:813f4b17ae65 33 {
mazdo25 1:813f4b17ae65 34 emitter.write(!emitter.read());
mazdo25 1:813f4b17ae65 35 }
mazdo25 1:813f4b17ae65 36
mazdo25 1:813f4b17ae65 37 //return an int representing the state of the emitter i.e is it on or off where 1 represents on and 0 represents off
mazdo25 1:813f4b17ae65 38 int returnEmitterState(void)
mazdo25 1:813f4b17ae65 39 {
mazdo25 1:813f4b17ae65 40 return emitter.read();
mazdo25 1:813f4b17ae65 41 }
mazdo25 1:813f4b17ae65 42
mazdo25 3:01b5e80d842d 43 void sample(void)
mazdo25 3:01b5e80d842d 44 {
mazdo25 3:01b5e80d842d 45 turnOn();
mazdo25 9:cefa177c1353 46 lineVoltage = receiver.read()*vREF;
mazdo25 3:01b5e80d842d 47 sampler.attach(callback(this, &lineSensor::turnOff),sampleTime);
mazdo25 3:01b5e80d842d 48 }
mazdo25 3:01b5e80d842d 49
mazdo25 4:208f5279143a 50 float calcLineVoltage(void)
mazdo25 1:813f4b17ae65 51 {
mazdo25 4:208f5279143a 52 lineVoltage = receiver.read()*vREF;
mazdo25 4:208f5279143a 53 return lineVoltage;
mazdo25 1:813f4b17ae65 54 }
mazdo25 1:813f4b17ae65 55
mazdo25 1:813f4b17ae65 56 float returnLineVoltage(void)
mazdo25 1:813f4b17ae65 57 {
mazdo25 1:813f4b17ae65 58 return lineVoltage;
mazdo25 1:813f4b17ae65 59 }
mazdo25 1:813f4b17ae65 60
mazdo25 1:813f4b17ae65 61 };