Code: #pragma config(Sensor, S4, sonarSensor, sensorSONAR) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/* Deklarationen */
int int_sonorval = 0;
/* Task zur Ermittlung des vom Sonar gemessenen Wertes */ task SonorChk() { int_sonorval = SensorValue[sonarSensor]; eraseDisplay(); nxtDisplayString (4," Gemessene Distanz:"); nxtDisplayString (5,""); nxtDisplayString (6," %i cm", int_sonorval); }
task main() { /* Hauptschleife - nach 1 Minute Programm auf alle Faelle beenden */ int int_now; int int_end; ClearTimer(T1); int_now = time10[T1]; int_end = int_now + 7000; while(int_now < int_end) { motor[motorC] = 50; motor[motorA] = 50; /* int_now = nClockMinutes;*/ int_now = time10[T1]; StartTask(SonorChk, 1); if (int_sonorval < 5 ) // Wenn die Distanz zu einem Objekt < 5 cm dann Stop { motor[motorC] = 0; motor[motorA] = 0; int_now = int_now + 7000; // while-Schleife nicht nochmal durchlaufen } } StopAllTasks(); }
|