Go Down

Topic: 10 servos, 10 potentiometers, issues (Read 3 times) previous topic - next topic

The Question

still getting and error

*analogRead(potpins[0]); //

*error: expected constructor, destructor, or type conversion before '(' token In function 'void loop()':


BTW I'm using 5k potentiometers, so I need to map the 0, 511 values for the potentiometer to 0, 179 of the servo position.

CaptainObvious

I'm not sure why you're getting errors.. did you remove the two analogReads like I showed? Well I commented them out..

Yup, that's the error.. make sure the two analogReads before your SETUP are commented out... or better yet, just delete them completely! Once I remove the comment lines for them, I get the same exact error.

You don't need the analogRead before Setup because.. well.. it does no good! You read all 9 sensors within about .2 seconds inside the loop anyways.

The Question

ok, now it works.

But anybody have anything for the "map" function to translate the 5k potentiometer to 180 positions on the servo?

PaulS

The map function call looks like this:

int newValue = map(value, fromLow, fromHigh, toLow, toHigh);

fromLow and fromHigh are the range to map from (0 to 1023 in your case). toLow and toHigh are the range to map to (0 to 180 in your case).

CaptainObvious

It won't matter what kind of resistance you're using, it will end up reading the same as long as it's a voltage divider (potentiometer).

potvals
  • = map(analogRead(potpins
  • ), 0, 1023, 0, 179);

    That's got to be inside the loop, replace:
    potvals
  • = analogRead(potpins
  • ); // remove completely

    with:
    potvals
  • = map(analogRead(potpins
  • ), 0, 1023, 0, 179);


    It needs to be the same position. Also, now when you want to write the values to a servo, you can use:

    servo0.Write(potvals[0]);
    servo1.Write(potvals[1]); // etc.

    Hopefully this helps!:)

Go Up