Buggy bois / Mbed 2 deprecated HEATS_2

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers lineSensor.h Source File

lineSensor.h

00001 class lineSensor
00002 {
00003     private:
00004     
00005     DigitalOut emitter;
00006     AnalogIn receiver;
00007     float static const vREF = 3.3f;
00008     float lineVoltage;
00009     Timeout sampler;
00010     
00011     public:
00012     float static const sampleTime = 0.00004f;
00013     
00014     lineSensor(PinName E, PinName R):emitter(E), receiver(R)
00015     {   
00016         sampler.detach();
00017     } 
00018     
00019     //Turn on the emitter i.e emit a light
00020     void turnOn(void)
00021     {
00022         emitter.write(1);   
00023     }
00024     
00025     //turn off the emitter i.e don't emit a light
00026     void turnOff(void)
00027     {
00028         emitter.write(0);
00029     }
00030     
00031     //toggle the emitter i.e if its on turn it off, if its off turn it on
00032     void toggleEmitter(void)
00033     {
00034         emitter.write(!emitter.read());
00035     }
00036     
00037     //return an int representing the state of the emitter i.e is it on or off where 1 represents on and 0 represents off
00038     int returnEmitterState(void)
00039     {
00040         return emitter.read();
00041     }
00042     
00043     void sample(void)
00044     {
00045         turnOn();
00046         lineVoltage = receiver.read()*vREF;
00047         sampler.attach(callback(this, &lineSensor::turnOff),sampleTime);
00048     }
00049     
00050     float calcLineVoltage(void)
00051     {
00052         lineVoltage = receiver.read()*vREF;
00053         return lineVoltage;
00054     }
00055     
00056     float returnLineVoltage(void)
00057     {
00058      return lineVoltage;
00059     }
00060     
00061 };