zhaw_st16b_pes2_10 / Mbed 2 deprecated IR-Sensors

Dependencies:   mbed

Committer:
EpicG10
Date:
Thu Mar 09 21:15:35 2017 +0000
Revision:
0:e1e981676769
Child:
1:558bf026649c
Read IR-sensor

Who changed what in which revision?

UserRevisionLine numberNew contents of line
EpicG10 0:e1e981676769 1 #include <cmath>
EpicG10 0:e1e981676769 2 #include "Distance_Sensors.h"
EpicG10 0:e1e981676769 3
EpicG10 0:e1e981676769 4
EpicG10 0:e1e981676769 5
EpicG10 0:e1e981676769 6 DistanceSensors::DistanceSensors()
EpicG10 0:e1e981676769 7 {
EpicG10 0:e1e981676769 8 }
EpicG10 0:e1e981676769 9
EpicG10 0:e1e981676769 10 DistanceSensors::DistanceSensors(AnalogIn* sensorVoltage, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, int number)
EpicG10 0:e1e981676769 11 {
EpicG10 0:e1e981676769 12 init(sensorVoltage, bit0, bit1, bit2, number);
EpicG10 0:e1e981676769 13 }
EpicG10 0:e1e981676769 14
EpicG10 0:e1e981676769 15 //initialise
EpicG10 0:e1e981676769 16 void DistanceSensors::init(AnalogIn* sensorVoltage, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, int number)
EpicG10 0:e1e981676769 17 {
EpicG10 0:e1e981676769 18 this->sensorVoltage = sensorVoltage;
EpicG10 0:e1e981676769 19 this->bit0 = bit0;
EpicG10 0:e1e981676769 20 this->bit1 = bit1;
EpicG10 0:e1e981676769 21 this->bit2 = bit2;
EpicG10 0:e1e981676769 22 }
EpicG10 0:e1e981676769 23
EpicG10 0:e1e981676769 24
EpicG10 0:e1e981676769 25 DistanceSensors::~DistanceSensors()
EpicG10 0:e1e981676769 26 {
EpicG10 0:e1e981676769 27 }
EpicG10 0:e1e981676769 28
EpicG10 0:e1e981676769 29
EpicG10 0:e1e981676769 30 float DistanceSensors::read()//Return the distance of an object
EpicG10 0:e1e981676769 31 {
EpicG10 0:e1e981676769 32 *bit0 = number & 1; // Set the first bit of the Sensors MUX
EpicG10 0:e1e981676769 33 *bit1 = number & 2; // Set the second bit of the Sensors MUX
EpicG10 0:e1e981676769 34 *bit2 = number & 4; // Set the third bit of the Sensors MUX
EpicG10 0:e1e981676769 35
EpicG10 0:e1e981676769 36 float Usensor=sensorVoltage->read(); //Read the Voltage from the selected distance sensor
EpicG10 0:e1e981676769 37 float Distance=-0.38f*sqrt(Usensor)+0.38f;
EpicG10 0:e1e981676769 38 return Distance;
EpicG10 0:e1e981676769 39 }
EpicG10 0:e1e981676769 40
EpicG10 0:e1e981676769 41 DistanceSensors::operator float()
EpicG10 0:e1e981676769 42 {
EpicG10 0:e1e981676769 43 return read();
EpicG10 0:e1e981676769 44 }
EpicG10 0:e1e981676769 45