//Ternary version of the card reader : //each digits (plate) is a ternary value. // black = 0 // grey = 1 // yellow = 2 #define Black 35 #define Grey 42 #define PlateWidth 14 int PulseCount; int Value1; int Value2; task main() { PulseCount = 0; start Count; SetSensor(SENSOR_2,SENSOR_LIGHT); SetSensor(SENSOR_1,SENSOR_TOUCH); GetValue(); StopAllTasks(); } task Count() { while (true) { until (SENSOR_1 == 0); Wait(5); PulseCount++; until (SENSOR_1 == 1); Wait(5); PulseCount++; } } void GetValue() { Value1 = 0; Value2 = 0; OnFwd(OUT_A); until (SENSOR_2 < Grey); until (SENSOR_2 > Grey); PulseCount = 0; until (PulseCount > PlateWidth*3/2); PulseCount = 0; // The seven first digits are encoded in Value1 repeat (7) { Value1 *= 3; if (SENSOR_2 > Grey) Value1++; if (SENSOR_2 > Black) Value1++; until (PulseCount > PlateWidth); PulseCount = 0; } // The remaining in Value2 repeat (7) { Value2 *= 3; if (SENSOR_2 > Grey) Value2++; if (SENSOR_2 > Black) Value2++; until (PulseCount > PlateWidth); PulseCount = 0; } until (PulseCount > 45); Off(OUT_A); }