sef

Dependencies:   mbed

Fork of Bewegungen_mit_Sensor by kings

Revision:
1:d40ff07e2fe0
Parent:
0:96f88638114b
Child:
2:365bf16abbf6
--- a/IRSensor.cpp	Tue Mar 21 14:57:54 2017 +0000
+++ b/IRSensor.cpp	Wed May 10 09:14:12 2017 +0000
@@ -1,67 +1,43 @@
-/*
- * IRSensor.cpp
- * Copyright (c) 2016, ZHAW
- * All rights reserved.
- */
+#include "IRSensor.h"
+#include <cmath>
 
-#include <cmath>
-#include "IRSensor.h"
-
+//E. Hess
+//IRSensor.cpp
 
-/**
- * Creates an IRSensor object.
- * @param distance an analog input object to read the voltage of the sensor.
- * @param bit0 a digital output to set the first bit of the multiplexer.
- * @param bit1 a digital output to set the second bit of the multiplexer.
- * @param bit2 a digital output to set the third bit of the multiplexer.
- * @param number the number of the sensor, either 0, 1, 2, 3, 4 or 5.
- */
-IRSensor::IRSensor(AnalogIn* distance, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, int number)
-{
-    init(distance, bit0, bit1, bit2, number);
-}
+//Konstruktor -> Erstellt ein IRSensor-Objekt
+//AnalogIn* distance -> Liest die Voltanzahl des Sensors aus
+//DigitalOut* bit0, bit1, bit2 -> Binär-Outputs wählen die 6 Sensoren an
+//Int number -> Sensornummer als int (0-5)
 
-
-IRSensor::IRSensor()
-{
-}
+IRSensor::IRSensor() {}
 
-void IRSensor::init(AnalogIn* distance, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, int number)
-{
-
-    this->distance = distance;  // set local references to objects
+IRSensor::IRSensor(AnalogIn* distance, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, int number) {
+    this->distance = distance;  //Weist den Objektvariablen, die eingegebenen Werte zu
     this->bit0 = bit0;
     this->bit1 = bit1;
     this->bit2 = bit2;
-
     this->number = number;
 }
 
-
-/**
- * Deletes the IRSensor object.
- */
+//Destruktor -> Löscht das IRSensor-Objekt
 IRSensor::~IRSensor() {}
 
-/**
- * Gets the distance measured with the IR sensor in [m].
- * @return the distance, given in [m].
- */
+//Initialisiert nachträglich
+void IRSensor::init(AnalogIn* distance, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, int number) {
+    this->distance = distance;  //Weist den Objektvariablen, die eingegebenen Werte zu
+    this->bit0 = bit0;
+    this->bit1 = bit1;
+    this->bit2 = bit2;
+    this->number = number;
+}
+
+//Distanzrechner
 float IRSensor::read()
 {
-    *bit0 = (number >> 0) & 1;
-    *bit1 = (number >> 1) & 1;
-    *bit2 = (number >> 2) & 1;
-
-    float d = -0.38f*sqrt(distance->read())+0.38f;  // calculate the distance in [m]
-    return d;
-}
+    *bit0 = (number >> 0) & 1;  //Vergleicht das Least-Significant-Bit von number mit 1 und setzt *bit0 (z.B. 5: 0000'0101 & 0000'0001 == 0000'0001)
+    *bit1 = (number >> 1) & 1;  //Vergleicht das zweite Bit von rechts
+    *bit2 = (number >> 2) & 1;  //Vergleicht das dritte Bit von rechts
 
-/**
- * The empty operator is a shorthand notation of the <code>read()</code> method.
- */
-IRSensor::operator float()
-{
-
-    return read();
-}
+    float d = distance->read();
+    return d;
+}
\ No newline at end of file