#define LIGHT IN_1 #define MOTOR OUT_A #define THRESHOLD 50 #define PowerDownDelay(minutes) asm { 0xb1, (minutes) } int curr_watch; int old_watch; int tmp; int state; sub step { if (state == 0) { if (LIGHT < THRESHOLD) { Rev(MOTOR, 1); while (LIGHT < THRESHOLD); Off(MOTOR); } state = 1; } else { if (LIGHT > THRESHOLD) { Rev(MOTOR, 1); while (LIGHT > THRESHOLD); Off(MOTOR); } state = 0; } } task main { Sensor(LIGHT, IN_LIGHT); /* Uncomment the next line to prevent the RCX from falling asleep after the default 15 minutes. Supplying power from an AC adapter is recommended. */ /* PowerDownDelay(0); */ Display(0); old_watch = Watch(); state = 0; while(1 == 1) { curr_watch = Watch(); if( curr_watch != old_watch ) { old_watch = curr_watch; /* We only want to step four times each five minutes, for 48 steps per hour. Don't step on minutes that are multiples of 5. */ tmp = (curr_watch / 5) * 5; if (tmp != curr_watch) { step(); } } } }