Buggy bois / Mbed 2 deprecated headache

Dependencies:   mbed

Committer:
mazdo25
Date:
Sat Mar 23 19:46:09 2019 +0000
Revision:
4:208f5279143a
Parent:
3:01b5e80d842d
Child:
5:f1613df66ceb
latest working, but line following not;

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:
mazdo25 3:01b5e80d842d 12 float static const sampleTime = 0.1f;
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 3:01b5e80d842d 46 sampler.attach(callback(this, &lineSensor::turnOff),sampleTime);
mazdo25 3:01b5e80d842d 47 }
mazdo25 3:01b5e80d842d 48
mazdo25 4:208f5279143a 49 float calcLineVoltage(void)
mazdo25 1:813f4b17ae65 50 {
mazdo25 4:208f5279143a 51 lineVoltage = receiver.read()*vREF;
mazdo25 4:208f5279143a 52 return lineVoltage;
mazdo25 1:813f4b17ae65 53 }
mazdo25 1:813f4b17ae65 54
mazdo25 1:813f4b17ae65 55 float returnLineVoltage(void)
mazdo25 1:813f4b17ae65 56 {
mazdo25 1:813f4b17ae65 57 return lineVoltage;
mazdo25 1:813f4b17ae65 58 }
mazdo25 1:813f4b17ae65 59
mazdo25 1:813f4b17ae65 60 };