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
/*
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)
}
}
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
Where'd you get the idea that map() takes that many parameters? You might start there:
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.
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.