Read Individual IR Sensors

How do I get the values of an individual IR sensor?


Assuming you are talking about a 3pi robot, you could use the read_line_sensors() function. See the Pololu AVR library command reference for more information:

- Ben

Now I can read the values, but they never seem to change, no matter what I do. Here is the code:

#include <pololu/orangutan.h>
#include <pololu/3pi.h>
#include <stdio.h>
int main(void) {
unsigned int sensors[5];

The reason why it isn’t working is that sensors is a pointer to an array of unsigned integers, so all you are doing is printing out the array’s address in memory, which does not change. You want to print out the actual array elements. For example:

printf("%u %u %u %u %u", sensors[0], sensors[1], sensors[2], sensors[3], sensors[4]);

Or, you could use a for-loop:

unsigned char i;
for (i = 0; i < 5; i++)
  printf("%u ", sensors[i]);

By the way, please put [ code ][ /code ] tags (without the spaces) around your code to make it more nicely formatted.

- Ben