Pages: [1]   Go Down
Author Topic: servo code help  (Read 1147 times)
0 Members and 1 Guest are viewing this topic.
scranton,pa
Offline Offline
Newbie
*
Karma: 2
Posts: 48
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/*
 
 
 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)
}
}
Logged

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 40
Posts: 5581
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

scranton,pa
Offline Offline
Newbie
*
Karma: 2
Posts: 48
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Belgium
Online Online
Edison Member
*
Karma: 68
Posts: 1920
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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 -

scranton,pa
Offline Offline
Newbie
*
Karma: 2
Posts: 48
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

there is one for left side and right motor
mright.write(valrpin);
  mleft.write(valgpin);
 
just don't know why i get the error
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 615
Posts: 49412
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Binary sketch size: 2874 bytes (of a 30720 byte maximum)
Logged

scranton,pa
Offline Offline
Newbie
*
Karma: 2
Posts: 48
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes there is one for each motor(servo)

i got it to work thanks

should i use something other then maps
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
should i use something other then maps

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

scranton,pa
Offline Offline
Newbie
*
Karma: 2
Posts: 48
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 615
Posts: 49412
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

scranton,pa
Offline Offline
Newbie
*
Karma: 2
Posts: 48
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: