// hopper.nqc // // LEGO train hopper dumper // // Author: John Koob // Date: Sep. 18, 2003 int DEBUG = 0; int DUMP_TIME = 2500; int CLAMP_TIME = 600; int ADJUST_TIME = 70; int DELAY_MIN = 1; int DELAY_CLAMP = 1; int DELAY_RUN = 15; int CLAMP = 1; int UNCLAMP = 0; task main() { SetSleepTime(0); SetSensor(SENSOR_1, SENSOR_TOUCH); start controller; } // tip the hopper wait and restore void dump() { int dump_time = DUMP_TIME; int adjust_time = ADJUST_TIME; int delay; // Tip the dumper PlaySound(SOUND_DOWN); Rev(OUT_B); OnFor(OUT_B, dump_time); delay = 100 * (DELAY_MIN + Random(4)); Wait(delay); // Restore dumper to horizontal PlaySound(SOUND_UP); Fwd(OUT_B); On(OUT_B); until(SENSOR_1 == 1); Off(OUT_B); PlaySound(SOUND_LOW_BEEP); // Final spurt to make level OnFor(OUT_B, adjust_time); delay = 100 * (DELAY_MIN + Random(3)); Wait(delay); } // clamp and unclamp void clamp(int clamp) { int clamp_time = CLAMP_TIME; int delay; if (clamp) Rev(OUT_A); else Fwd(OUT_A); PlaySound(SOUND_CLICK); OnFor(OUT_A, clamp_time); delay = 100 * (DELAY_CLAMP + Random(2)); Wait(delay); } // main controller that decides how long to wait between runs task controller() { int delay; // while (true) // { delay = 100 * (DELAY_RUN + Random(5)); clamp(CLAMP); dump(); clamp(UNCLAMP); Wait(delay); // } }