/* ==================================================================== * testlight.c * * Test the Lego Light Sensor * * Light sensor on port 2 * * Copyright: Gary Harkin * 2005 * * ===================================================================== */ #include #include #include #include #include #include #define LIGHTSENS SENSOR_2 static void display_range (int r) { cls(); lcd_number (r, unsign, e0); } int main(int argc, char *argv[]) { int x; /* * Set the sensor passive so that it can recalibrate. Takes about 1 second. */ ds_passive (&LIGHTSENS); sleep (2); /* * Now make it active and put it in percent mode for reading. */ ds_active (&LIGHTSENS); /* Testing code. For hard surfaces, it calibrates to a raw value of about 5 for a 6 inch separation. It maxes out at about 80, but drops off in accuracy rapidly after about 6 feet. */ while (1) { x = LIGHT(LIGHTSENS); display_range (x); sleep (1); } return 0; }