/********************************************/ /* */ /* written by Roy Merrell */ /* sample code for the mechatronics ir lab */ /* last modified 18 Oct 2001 */ /********************************************/ int i; /* i is a counter */ int center /* center holds value of the center ir */ void main() { printf("press start to read center ir"); while(!start_button()) {} /* hold here until start is pressed */ while(1) { /* run in a continous loop */ center = 0; /* initialize center */ if(start_button()) { /* take readings if start is pushed */ for(i=0;i<10;i++) { /* loop for running 10 times */ center += analog(2); /* sums the value of the 10 runs */ } center /= i; /* divide by i to take the average */ printf("c=%d\n", center); /* print the results */ } } }