Code-Work @ lowlevel

This commit is contained in:
sicarius 2007-02-13 19:10:02 +00:00
parent 54a7ea32d4
commit 5c33efe58d
13 changed files with 1079 additions and 480 deletions

View file

@ -1,11 +1,35 @@
#include "ballsensor.h"
Ballsensor::Ballsensor() {
Ballsensor::Ballsensor() {
// Umrechnungstabelle position i in Winkel
winkel[0] = 0;
winkel[1] = 30;
winkel[2] = 60;
winkel[3] = 100;
winkel[4] = 180;
winkel[5] = 260;
winkel[6] = 300;
winkel[7] = 330;
}
Ballsensor::~Ballsensor() {
}
int Ballsensor::getBallwinkel() {
return 0;
// Erstelle ein Array für die Sensorwerte
int sensor[NUM_BALLSENSOR];
int result = 0; // und einer Variable fürs Ergebnis
int current = 1024; // Setze aktuellen Wert auf Maximum
// Analoge Sensoren abfragen und eintragen
for(int i=0;i<NUM_BALLSENSOR;i++) sensor[i] = board.GetADC(i);
// Suche den kleinsten Wert
for(int i=0;i<NUM_BALLSENSOR;i++) {
// Wenn der Sensorwert kleiner ist ist der Ball näher dran
if(sensor[i] < current) result = i; // Ergebnis ist erstmal index
}
// Gebe den Winkel zum index result zurück
return winkel[result];
}

View file

@ -3,11 +3,15 @@
#include "../hal/board.h"
// Anzahl der Ballsensoren
#define NUM_BALLSENSOR 8
extern Board board;
class Ballsensor
{
private:
int winkel[NUM_BALLSENSOR];
public:
Ballsensor();
~Ballsensor();

View file

@ -3,6 +3,7 @@
#include "../hal/board.h"
#include "ballsensor.h"
#include "../hal/maussensor.h"
#include "../global.h"
extern Board board;