coding/algorithm interpreting sensors. where to start?

I'm really not sure of the best way to code my next project so would appreciate a steer in the right direction. I hope this makes sense.

I've two sensors that describe a point on the surface of a cylinder. Sensor A, a rotary encoder that gives the angle around the circumference and sensor B, a linear encoder that gives the position up and down the surface.

I want to be able to do various operations depending on where I am on the surface. Let's say sensor A gives 0-100 and sensor B 0-30. Each thing on the surface is a zone. Say object 1 is at 5<A<10 and 3<B<7. How would I go about finding if I was at object 1 (or 2, or 3, etc) without using 3000 'if' statements?

Secondly I want to find each object once per revolution so once it has been hit it is ignored until the next revolution. The rotation is one way so sensor A only increments.

I'm struggling with the general way to go about this. I'm more of a hardware person. Do I need some kind of look up table? If I need less range on the sensors I can do that.

I would say you need to know about compound if statements

 if( a> 62 && a< 100) // we have found the first object

Thanks Mike that'll simplify things a bit. Can I have several &&'s as I need to find it in A and B. Googling && for syntax help doesn't seem to work that well

if( a> 5 && a< 10 && b>3 && b<7) // found the first object
if( a> 15 && a< 17 && b>2 && b<4) // found the second object
if( a> 62 && a< 70 && b>8 && b<10) // found the third object
... and so on

Yes that looks fine although I normally put each compair in brackets. You can also use || for ORing conditions.

Do I need some kind of look up table?

That would be a more elegant way to do it - an array of structs with the min and max of each sensor and a corresponding state that you could use in a switch would make your code simpler. Until you've got a bit more coding experience though, it might be easier to stick with the multiple if statements,

You could look into using an array - however I agree with the comments by wildbill about sticking to the multiple if statements until you're comfortable with them.

However, should you want to investigate further, here is a simple program showing one way to do it. It is written in C, but works as a C++ program. To do it in C++ would (or rather could!) involve use of classes, and would be relatively trivial to write once you have some more experience. It has been written to compile on a desktop system, but you can extract the relevant language constructs and use them in the arduino.

The other tip I would suggest - if I understand your application correctly, overlapping areas would be an error. If that is the case, I would add a check in the setup() routine to walk through the array and confirm the lack of overlap.

Finally, you pointed out in your original message that you want to drigger the actions once for each revolution for each area the pointer comes across. If that is the case, then you could setup a flag for each area, and check it when an area is found. If the flag is set, do nothing, otherwise set the flag and carry out the tasks. As the cylinder passes through the zero point, reset all the flags (this assumes no area crosses the zero point).

// Actually written out as a C program, but of course works
// as c++. compiles using:
//                         g++ -o areatest area.cpp
// (assuming this is saved as area.cpp)

#include <stdio.h>

// Structures for point and area
// This is a way to collect the positions of the two
// encoders for a point

struct POINT { 
  int a;
  int b;
};

// An AREA is defined by the coordinates of the top left
// and bottom right corners, and is given an id

struct AREA {
  int id;
  POINT topLeft;
  POINT bottomRight;
};

// Declaration of the function which will identify
// which zone includes the point being checked.

int inZone(POINT);

// This is a static array of areas. There is
// no check to see if the areas overlap

AREA zones[] = {
  // id , topLeft, bottomRight 
  {1, {2,3},  {4,5}},
  {2, {5,5},  {10,10}},
  {3, {5,10}, {10,15}},
  {4, {5,15}, {10,10}},
  {5, {10,5}, {15,10}},
  {6, {20,20},{25,25}}
};

// Test routine in main to show how the function works

int main(int argc, char *argv[])
{

  POINT myPoint = {6,8}; // Point to check
  int myZone;            // save the zone returned 

  myZone = inZone(myPoint); // Get the zone

  if (myZone > 0) // If the zone isn't found it returns -1
    printf("myPoint is in zone %d\n", myZone);
  else
    printf("myPoint is not in any of the zones!\n");

  return 0;
}

int inZone(POINT point)
{

  // Step through the zones[] array. Note - if there
  // are overlapping zones, the first one found will
  // be returned

  for (int i = 0; i <= sizeof(zones); i++) {
    if ((point.a > zones[i].topLeft.a) &&
        (point.b > zones[i].topLeft.b) &&
        (point.a <= zones[i].bottomRight.a) &&
        (point.b <= zones[i].bottomRight.b))
      return(zones[i].id);
  }
    
  return(-1); // not in any of the areas in zones[]
}