Go Down

Topic: servo code help (Read 1 time) previous topic - next topic

pittom

I keep getting a rservonew:38: error: expected `;' before '}' token   and don't know why here is code.
I want 2 input voltage  == each other if so move servo
Code: [Select]
/*


4 inputs with with (and &&) and 2 outputs
servo

*/
#include <Servo.h>

Servo mright; 
Servo mleft;
int pos = 90;  // servo start posion


int rpin = A5;      // 2red come in from rovio 
int gpin = A4;   // 5green 
int valrpin = 0;          // variable to read the value from the analog pin
int valgpin = 0;

void setup() {
   
  mright.attach(11);
  mleft.attach(10);
  pinMode(A5, INPUT);
  pinMode(A4, INPUT);
   
}

void loop(){
  // read rovio input
  valrpin = analogRead(rpin);
  valgpin = analogRead(gpin);
  if (valrpin == valgpin){
  valrpin = map(val, 0, 306, 408, 714, 1023, 90, 110, 120, 130, 140);   // forward
  valgpin = map(val, 0, 306, 408, 714, 1023, 90, 110, 120, 130, 140);
  mright.write(valrpin);
  mleft.write(valgpin);
  delay(15)
}
}

cr0sh


I keep getting a rservonew:38: error: expected `;' before '}' token   and don't know why here is code.
I want 2 input voltage  == each other if so move servo


Where'd you get the idea that map() takes that many parameters? You might start there:

http://arduino.cc/en/Reference/map
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

pittom

I am new and learning, getting better thanks to all the good people on forums

Jantje

also
there should be a ; behind delay(15)
and there is 1 } to many at the end of the file
Code: [Select]
  mleft.write(valgpin);
  delay(15);
}

Best regards
Jantje
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

pittom

there is one for left side and right motor
mright.write(valrpin);
  mleft.write(valgpin);

just don't know why i get the error

PaulS

Quote
there is one for left side and right motor
mright.write(valrpin);
  mleft.write(valgpin);

just don't know why i get the error

There is one what for each motor?

Have you read any of the responses? If there was something you did not understand, say so.

When I add the missing ;, put the { on new lines where they belong (in my opinion), and correct the map calls, I only get this error:
Code: [Select]
Binary sketch size: 2874 bytes (of a 30720 byte maximum)

pittom

yes there is one for each motor(servo)

i got it to work thanks

should i use something other then maps

dxw00d

Quote
should i use something other then maps


Probably, but you haven't told us what you are trying to achieve.

pittom

I have 2 inputs each go 2v to 5v and 2 servos to drive left/right motors

servo set pos 90 when input 1 and input 2 are == at 2v move servo to pos 100
if input 1 and 2 are not == stay at pos 90

              volts             pos
       
                2                100
                3                120
                4                130
                5                145
if input 1 and 2 are not == stay at pos 90

i hope this explains what i am trying to do

PaulS

Quote
should i use something other then maps

There is nothing wrong with using map. The only problem is with the way that you were using it. The map() function takes 5 arguments, not 11 as you were supplying.

The first argument is the value to be mapped - the output from the analogRead function, for example.

The next two arguments define the range you want to map from - 0 to 1023 if the value to map is from analogRead.

The final two arguments define the range to map to - 100 to 145 in your example.

If the minimum value ever returned by analogRead corresponds to 2V, then the value will be around 400, and you can use that value as the lower end of the from range.

Quote
if input 1 and 2 are not == stay at pos 90

They probably will almost never be. It sounds like what you want, though, is to do nothing if the difference is less than some value, rather than the two values being equal.

I suggest that your biggest problem right now is not understanding what analogRead returns. It does not return a voltage, and the values are not 1V, 2V, etc.

pittom

thanks i see what you mean about map() function now

Go Up