/* A program that responds to the presence of an obstacle. If an obstacle is not detected, the robot beeps twice. If an obstacle is detected, the robot turns on a light for 3 seconds. */ #include #include int main () { printf ("Program to respond to a detected obstacle\n"); rConnect ("/dev/rfcomm0"); /* Obtain sensor data for obstacles on the left of the Scribbler 2 robot */ int sensorReading = rGetIRTxt ("left", 5); /* Check if obstacle present */ if (sensorReading) { printf ("obstacle detected\n"); /* turn on light */ rSetLEDFront (1); /* wait 3 seconds by beeping with zero frequency */ rBeep (3.0, 0); /* turn off light */ rSetLEDFront (0); } else { printf ("no obstacle found\n"); rBeep (1.5, 880); rBeep (1.5, 1760); } printf ("Processing completed\n"); return 0; }