// Values set by calibration program int AvgLevel1, AvgLevel3; int Diff1, Diff3; int PulseCnt1 = 0, PulseCnt3 = 0; int Display; task main () { SetSensor (SENSOR_1, SENSOR_LIGHT); SetSensor (SENSOR_3, SENSOR_LIGHT); SetUserDisplay (Timer(1), 0); start Monitor_Rotations; ClearTimer(1); OnRev (OUT_A+OUT_C); until (PulseCnt1 > 20); Off(OUT_A); until (PulseCnt3 > 100); OnRev (OUT_A); until (PulseCnt1 > 190); Off(OUT_C); OnFwd (OUT_A); until (PulseCnt1 > 290); OnFwd (OUT_C); OnFwd (OUT_A); until (PulseCnt3 > 470); Off(OUT_A + OUT_C); Display = Timer(1); SetUserDisplay(Display,1); PlaySound (SOUND_DOUBLE_BEEP); ClearMessage(); until (Message()==1); PulseCnt1 = 0; PulseCnt3 = 0; OnRev (OUT_A+OUT_C); until (PulseCnt3 > 30); Off(OUT_C); until (PulseCnt1 > 100); Off(OUT_A); OnFwd (OUT_C); until (PulseCnt3 > 100); OnFwd (OUT_A); until (PulseCnt3 > 120); Off(OUT_A + OUT_C); } task Monitor_Rotations () { SetEvent(1, SENSOR_1, EVENT_TYPE_HIGH); SetUpperLimit(1, AvgLevel1 + (Diff1 / 4)); SetHysteresis(1, Diff1 / 4); SetEvent(2, SENSOR_1, EVENT_TYPE_LOW); SetLowerLimit(2, AvgLevel1 - (Diff1 / 4)); SetHysteresis(2, Diff1 / 4); SetEvent(3, SENSOR_3, EVENT_TYPE_HIGH); SetUpperLimit(3, AvgLevel3 + (Diff3 / 4)); SetHysteresis(3, Diff3 / 4); SetEvent(4, SENSOR_3, EVENT_TYPE_LOW); SetLowerLimit(4, AvgLevel3 - (Diff3 / 4)); SetHysteresis(4, Diff3 / 4); while (true) { monitor( EVENT_MASK(1) | EVENT_MASK(2) | EVENT_MASK(3) | EVENT_MASK(4) ) { while (true) { Wait(100); } } catch ( EVENT_MASK(1) | EVENT_MASK(2) ) { PulseCnt1++; } catch ( EVENT_MASK(3) | EVENT_MASK(4) ) { PulseCnt3++; } } }