Ausreißer sind ein Problem. Ich habe dafür an anderer Stelle mal Folgendes entwickelt, aber das geht sicher noch raffinierter:
Code:
#include "asuro.h"
#define MAXDIFF 90

int main(void)
{
  int abstand, abstand_alt, diff, zaehler=0;
  Init();
  abstand = Chirp();
   
  while(TRUE)
  {
    abstand_alt = abstand;
	abstand = Chirp();	++zaehler;
	diff = abstand - abstand_alt;
	
	if( (abstand>15) && (abs(diff)<MAXDIFF) )
	{
	  StatusLED(GREEN);
	  MotorDir(FWD, FWD);
	  MotorSpeed(150, 150);
	}
	else if( (abstand>10) && (abstand<=15) && (abs(diff)<MAXDIFF) )
	{
	  StatusLED(YELLOW);
	  MotorDir(FWD, FWD);
	  MotorSpeed(150, 100);
	  Msleep(10);
	}
	else
	{
	  StatusLED(RED);
	  MotorDir(RWD, RWD);
	  MotorSpeed(150, 100);
	  Msleep(10);
	}
	
	if (zaehler > 800)
	{
		StatusLED(RED);
		BackLED(ON,ON);
	    MotorDir(RWD, RWD);
	    MotorSpeed(200, 250);
	    Msleep(10);
		BackLED(OFF,OFF);
	}
	if (zaehler > 810)
	{
		StatusLED(RED);
		BackLED(ON,ON);
	    MotorDir(RWD, RWD);
	    MotorSpeed(250, 200);
	    Msleep(10);
		BackLED(OFF,OFF);
				
		if(zaehler > 820)
		  zaehler = 0;
	}
  }
  return 0;
}