// APPENDIX // // Bricx Command Center 3.3.7.16 // // Input __________________________________ Outputs ____________________________ // // S1=left US-Sensor OUT_A=Motor // S2=right US-Sensor // S3=TouchSensor // // CODE: //______________________________________________________________________________ bool active; int power; //______________________________________________________________________________ void move_info(bool right_to_left) { if(right_to_left == true) { OnRev(OUT_A, power); } else { OnFwd(OUT_A, power); } Wait(800); while(1) { if(SENSOR_3 == true) { Off(OUT_A); break; } } Wait(1000); } //______________________________________________________________________________ void start_move_info(bool dir) { active = true; move_info(dir); active = false; } //______________________________________________________________________________ task automatic() { while(1) { repeat(60) { Wait(1000); } if(active == false) { start_move_info(false); } } } //______________________________________________________________________________ task main() { SetSensorLowspeed(S1); SetSensorLowspeed(S2); SetSensor(S3,SENSOR_TOUCH); byte distance = 20; power = 60; active = false; ClearScreen(); TextOut(30,LCD_LINE3,"APPENDIX"); TextOut(15,LCD_LINE5,"is running..."); if(SENSOR_3 == 0) { move_info(false); } StartTask(automatic); while (true) { if(SensorUS(S1) < distance) { start_move_info(false); } else { if(SensorUS(S2) < distance) { start_move_info(true); } } } }