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.
IRSensor.cpp
- Committer:
- wengefa1
- Date:
- 2020-02-26
- Revision:
- 0:c88f41ac2cb7
- Child:
- 2:f381fc3a8eaf
File content as of revision 0:c88f41ac2cb7:
/*
* IRSensor.h
* Copyright (c) 2020, ZHAW
* All rights reserved.
*/
#include <cmath>
#include "IRSensor.h"
using namespace std;
/**
* Creates and initialises the driver to read the distance sensors.
* @param distance the analog input to read a distance value from.
* @param bit0 a digital output to control the multiplexer.
* @param bit1 a digital output to control the multiplexer.
* @param bit2 a digital output to control the multiplexer.
* @param number the number of the sensor. This value must be between 0 and 5.
*/
IRSensor::IRSensor(AnalogIn& distance, DigitalOut& bit0, DigitalOut& bit1, DigitalOut& bit2, int number) : distance(distance), bit0(bit0), bit1(bit1), bit2(bit2) {
this->number = number;
}
/**
* Deletes this IRSensor object and releases all allocated resources.
*/
IRSensor::~IRSensor() {}
/**
* This method reads from the distance sensor.
* @return a distance value, given in [m].
*/
float IRSensor::read() {
// bitte implementieren!
bit0 = (number >> 0)&1;
bit1 = (number >> 1)&1;
bit2 = (number >> 2)&1;
float dist = -0.58f*(sqrt(distance)+0.58f);
return dist;
}