task main () { int RawVal; int Switch1, Switch2, PFremote; SetSensorLight (S1); while (true) { RawVal=GetInput (S1, RawValue); NumOut (10, LCD_LINE8, RawVal, true); /* simple code if(RawVal > 950) {Switch1=0; Switch2=0; PFremote=0;} else if(RawVal > 810) {Switch1=1; Switch2=0; PFremote=1;} else if(RawVal > 750) {Switch1=1; Switch2=1; PFremote=4;} else if(RawVal > 690) {Switch1=1; Switch2=-1; PFremote=7;} else if(RawVal > 600) {Switch1=0; Switch2=1; PFremote=3;} else if(RawVal > 400) {Switch1=0; Switch2=-1; PFremote=6;} else if(RawVal > 310) {Switch1=-1; Switch2=1; PFremote=5;} else if(RawVal > 260) {Switch1=-1; Switch2=-1; PFremote=8;} else {Switch1=-1; Switch2=0; PFremote=2;} */ // more balanced code if(RawVal > 690) { if(RawVal > 810) { if(RawVal > 950) {Switch1=0; Switch2=0; PFremote=0;} else {Switch1=1; Switch2=0; PFremote=1;} } else { if(RawVal > 750) {Switch1=1; Switch2=1; PFremote=4;} else {Switch1=1; Switch2=-1; PFremote=7;} } } else if(RawVal <= 600) { if(RawVal > 310) { if(RawVal > 400) {Switch1=0; Switch2=-1; PFremote=6;} else {Switch1=-1; Switch2=1; PFremote=5;} } else { if(RawVal > 260) {Switch1=-1; Switch2=-1; PFremote=8;} else {Switch1=-1; Switch2=0; PFremote=2;} } } else {Switch1=0; Switch2=1; PFremote=3;} NumOut (60, LCD_LINE8, PFremote); RectOut (33, 15, 12, 40); RectOut (55, 15, 12, 40); RectOut (35, 31+11*Switch1, 8, 8); RectOut (36, 32+11*Switch1, 6, 6); RectOut (57, 31+11*Switch2, 8, 8); RectOut (58, 32+11*Switch2, 6, 6); Wait(200); } }