/* Techno-stuff DIRPD Obsatcle Avoiding Program */ /* Written by: Miles */ /* Version 1.1 */ /* Please adjust the DIRPD value numbers to your own until the next version comes out. */ #define REV_TIME 50 #define TRN_TIME 50 + Random(100) #define DIRPD SENSOR_1 task main() { // Your DIRPD sensor should be on port 1. SetSensor(DIRPD, SENSOR_LIGHT); OnFwd (OUT_AC); // The robot goes forward. while (true) { if (DIRPD == 0) // if the DIRPD senses an object in front... { OnRev (OUT_AC); Wait (REV_TIME); OnFwd (OUT_A); Wait (TRN_TIME); OnFwd (OUT_C); } if (DIRPD == 22) // if the DIRPD senses an object to the left... { OnRev (OUT_C); Wait (TRN_TIME); OnFwd (OUT_C); } if (DIRPD == 48) // if the DIRPD senses an object to the right... { OnRev (OUT_A); Wait (TRN_TIME); OnFwd (OUT_A); } } }