/* This program reads the center light sensor on the front of the Scribbler 2 robot and reports the brightness category of the current environment. */ #include #include "MyroC.h" int main () { printf("This program reports the brightness of the Scribbler 2's environment\n"); /* connect to the Scribbler 2 robot */ rConnect ("/dev/rfcomm0"); /* obtain the average of 3 readings of the center light sensor */ int lightReading = rGetLightTxt ("center", 3); printf ("The reading from the center light sensor is %d (out of 65535)\n", lightReading); /* determine the brightness category */ switch (lightReading/10000) { case 0: printf ("The area is very bright\n"); break; case 1: printf ("The area is bright\n"); break; case 2: printf ("The area has moderate lightt\n"); break; case 3: printf ("The area has dim light\n"); break; case 4: printf ("The area is dark\n"); break; case 5: printf ("The area is very dark\n"); break; case 6: printf ("The area is pitch black\n"); break; default: printf ("computational error --- no category identified\n"); break; } }