Const setpoint = 5 Const measure = 6 Const dif = 7 With RCX .ComPortNo = 1 ' COM port 1 .LinkType = 0 ' 0 = IR .PBrick = 1 ' 1 = RCX, 0 = CyberMaster .InitComm ' Initialise the COM port .SelectPrgm SLOT3 .BeginOfTask MAIN .SetSensorType SENSOR_2, LIGHT_TYPE .SetSensorMode SENSOR_2, RAW_MODE, 0 .SetVar setpoint, CON, 1 '1=N,2=NE,3=E,4=SE,5=S,6=SW,7=W,8=NW .SetVar measure, CON, 0 .SetVar dif, CON, 0 .StartTask 1 .EndOfTask 'Main .BeginOfTask 1 .Loop CON, forever 'North .If SENVAL, SENSOR_2, EQ, CON, 863 .SetVar measure, CON, 1 .EndIf .If SENVAL, SENSOR_2, EQ, CON, 862 .SetVar measure, CON, 1 .EndIf .If SENVAL, SENSOR_2, EQ, CON, 861 .SetVar measure, CON, 1 .EndIf 'North-East .If SENVAL, SENSOR_2, EQ, CON, 920 .SetVar measure, CON, 2 .EndIf .If SENVAL, SENSOR_2, EQ, CON, 919 .SetVar measure, CON, 2 .EndIf .If SENVAL, SENSOR_2, EQ, CON, 918 .SetVar measure, CON, 2 .EndIf 'East .If SENVAL, SENSOR_2, EQ, CON, 810 .SetVar measure, CON, 3 .EndIf .If SENVAL, SENSOR_2, EQ, CON, 809 .SetVar measure, CON, 3 .EndIf .If SENVAL, SENSOR_2, EQ, CON, 808 .SetVar measure, CON, 3 .EndIf 'South-East .If SENVAL, SENSOR_2, EQ, CON, 856 .SetVar measure, CON, 4 .EndIf .If SENVAL, SENSOR_2, EQ, CON, 855 .SetVar measure, CON, 4 .EndIf .If SENVAL, SENSOR_2, EQ, CON, 854 .SetVar measure, CON, 4 .EndIf 'South .If SENVAL, SENSOR_2, EQ, CON, 818 .SetVar measure, CON, 5 .EndIf .If SENVAL, SENSOR_2, EQ, CON, 817 .SetVar measure, CON, 5 .EndIf .If SENVAL, SENSOR_2, EQ, CON, 816 .SetVar measure, CON, 5 .EndIf 'South-West .If SENVAL, SENSOR_2, EQ, CON, 830 .SetVar measure, CON, 6 .EndIf .If SENVAL, SENSOR_2, EQ, CON, 829 .SetVar measure, CON, 6 .EndIf .If SENVAL, SENSOR_2, EQ, CON, 828 .SetVar measure, CON, 6 .EndIf 'West .If SENVAL, SENSOR_2, EQ, CON, 787 .SetVar measure, CON, 7 .EndIf .If SENVAL, SENSOR_2, EQ, CON, 786 .SetVar measure, CON, 7 .EndIf .If SENVAL, SENSOR_2, EQ, CON, 785 .SetVar measure, CON, 7 .EndIf 'North-West .If SENVAL, SENSOR_2, EQ, CON, 887 .SetVar measure, CON, 8 .EndIf .If SENVAL, SENSOR_2, EQ, CON, 886 .SetVar measure, CON, 8 .EndIf .If SENVAL, SENSOR_2, EQ, CON, 885 .SetVar measure, CON, 8 .EndIf 'The sensor value is stored in register 'measure' 'the target value in 'setpoint' .SetVar dif, VAR, measure 'dif=measure-setpoint .SubVar dif, VAR, setpoint .If VAR, dif, EQ, CON, 0 .PlaySystemSound 0 .EndIf .EndLoop .EndOfTask End With