Go Down

Topic: Ivalue required as left operand of assignment error (Read 1 time) previous topic - next topic

Tonyodonnell01

I have some code and when I compile it I get this error: Ivalue required as left operand of assignment error. This is only a small part of the code.


Code: [Select]

void moveServoLeftTo(int angle, int duration){
  // command the servo to move to the given angle for the given number of milliseconds 
   LeftServo1.write(120);
   for (; 120 > 0; 120 -= 20){  // loop for the given number of milliseconds by subtracting 20ms each iteration
LeftServo.refresh();             // call the service routine to move the servo
delay(20);           // wait 20 milliseconds  between each refresh


I did not come up with or type this code, I am filling in this code.
Thanks for helping.

Nick Gammon

Code: [Select]
120 -= 20

You can't subtract a constant from another constant.

Tonyodonnell01

Now I getting another error when I compile it. I am getting 'class Servo' has no member named 'refresh'.

LeftServo1.refresh();

Thanks for the help.

michael_x


I am getting 'class Servo' has no member named 'refresh'.

And what's the problem?
'class Servo' has no member named 'refresh'.

Error message cannot be much clearer. ( member means method means function )

BTW: You're using variables LeftServo and LeftServo1. Is that your intention?

wildbill

Sounds like your code is from a fairly old source - refresh used to be part of the servo library, no longer needed - just delete the calls to it.

Tonyodonnell01

Here is the whole code. As of right now when I compile it I don't get any errors, so all I have to do is wire everything up and test it. Thank you again for all your help.

Code: [Select]

#include <Servo.h>     // includes the servo libs
Servo LeftServo1;       // name the servo
Servo RightServo2;      // name the servo
int ultraSoundSignal = 7; // Ultrasound signal pin
int val = 0;
int val2 = 0;
int ultrasoundValue = 0;
int timecount = 0; // Echo counter
int ledPin = 13; // LED connected to digital pin 13
int lightSense = 2;
int headLight = 8;

void setup(){
   pinMode(6,OUTPUT);
   pinMode(5,OUTPUT);
   LeftServo1.attach(6); // Attaches the Left Servo to PWM pin 6 on the Arduino
   RightServo2.attach(5); // Attaches the Right Servo to PWM pin 5 on the Arduino
   pinMode(headLight, OUTPUT);
   pinMode(lightSense, INPUT);
   Serial.begin(9600);                  // Sets the baud rate to 9600
   pinMode(ledPin, OUTPUT);            // Sets the digital pin as output
}

void moveServoLeftTo(int angle, int duration){
  // command the servo to move to the given angle for the given number of milliseconds 
   LeftServo1.write(120);
   for (; 120 > 0; 120 - 20){  // loop for the given number of milliseconds by subtracting 20ms each iteration
LeftServo1;// LeftServo1.refresh(); When you said remove refresh did you mean the whole thing or just .refresh()             // call the service routine to move the servo
delay(20);           // wait 20 milliseconds  between each refresh
   }
}
void moveServoRightTo(int angle, int duration){
  // command the servo to move to the given angle for the given number of milliseconds 
   RightServo2.write(angle);
   for( ; 110 > 0; 110 - 20){  // loop for the given number of milliseconds by subtracting 20ms each iteration
RightServo2;            // call the service routine to move the servo
delay(20);           // wait 20 milliseconds  between each refresh


}
void loop() {

// Ping))) functions: Doing more than I need it to, I think, but code

timecount = 0;
val = 0;
pinMode(ultraSoundSignal, OUTPUT);   // Switch signalpin to output

  digitalWrite(ultraSoundSignal, LOW);  // Send low pulse
  delayMicroseconds(2);                 // Wait for 2 microseconds
  digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
  delayMicroseconds(5);                 // Wait for 5 microseconds
  digitalWrite(ultraSoundSignal, LOW);  // Holdoff

  pinMode(ultraSoundSignal, INPUT);     // Switch signalpin to input
  val = digitalRead(ultraSoundSignal);  // Append signal value to val
  while(val == LOW) {                   // Loop until pin reads a high value
    val = digitalRead(ultraSoundSignal);
}

  while(val == HIGH) {                  // Loop until pin reads a high value
  val = digitalRead(ultraSoundSignal);
  timecount = timecount +1;           // Count echo pulse time
}

ultrasoundValue = timecount;          // Append echo pulse time to ultrasoundValue

if(timecount > 0){
  digitalWrite(ledPin, HIGH);
}

//delay(1);

// Servo functions: The basics

  if(ultrasoundValue > 500){
moveServoLeftTo(45,50);   // move the left servo to 45 degrees for 500 milliseconds
moveServoRightTo(180,50);  // moveRightTo function is left as an excercise ;)
  }
 
  if(ultrasoundValue < 500){
      moveServoLeftTo(180,40);
      moveServoRightTo(180,40);

  }
   
     if(ultrasoundValue < 100){
      moveServoLeftTo(180,100);
      moveServoRightTo(45,100);
      //moveServoLeftTo(45,50);
      //moveServoRightTo(180,50);

  }
// Headlight - Turns on when photoresistor is triggered 
// Doesn't seem to work on the same circuit... not sure why yet.
/*  val2 = digitalRead(lightSense);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(headLight, LOW);  // turn LED OFF
  } else {
    digitalWrite(headLight, HIGH); // turn LED ON
  */
   
}

James C4S

#6
May 06, 2012, 09:05 pm Last Edit: May 06, 2012, 09:07 pm by James C4S Reason: 1
Code: [Select]
  for (; 120 > 0; 120 - 20){  // loop for the given number of milliseconds by subtracting 20ms each iteration
LeftServo1;// LeftServo1.refresh(); When you said remove refresh did you mean the whole thing or just .refresh()             // call the service routine to move the servo
delay(20);          // wait 20 milliseconds  between each refresh
  }

While this code may compile, it is certainly not doing what you expect.  In fact, this would be an infinite loop.  for() loops need a variable to be practical.

You probably meant to use something like:
Code: [Select]
for (int i=120; i > 0; i = i-20) {

http://arduino.cc/en/Reference/For
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Tonyodonnell01

Thanks, I'll try it. I was having a little trouble with that and that was going to be my next question but you got to be for I did. Thanks for help. 

Tonyodonnell01

Yes, I know I am double posting. I was hoping somebody would have replied by now. Do you know if it would be possible to replace the servos with motors?

P.S. By the way James C4S thanks for the help. I saw a tremendous improvement once I changed it. All I have to do is come of with a debounce because the servos are moving all over the place.

Nick Gammon


Yes, I know I am double posting. I was hoping somebody would have replied by now.


Replied to what? You said:

Quote
As of right now when I compile it I don't get any errors, so all I have to do is wire everything up and test it. Thank you again for all your help.


Sounds like you got rid of the compile errors, and were going to test something. Where is the question?

Tonyodonnell01

Sorry didn't realized that it didn't post correctly. My question was would it be possible to replace the servos with motors and do it by attaching the motors to the same pins as the servos or do I need to write some code again?

WizenedEE


Sorry didn't realized that it didn't post correctly. My question was would it be possible to replace the servos with motors and do it by attaching the motors to the same pins as the servos or do I need to write some code again?


Well, depending on how you have the motor wired (as always), you can just replace calls to Servo.write to either analogWrite or digitalWrite. That will make the motor move (assuming it's attached to a transistor/h-bridge/whatever), but maybe not how you want it to. How do you want the motor to replace the servo? (Making a DC motor move like a servo with it's "go to there" command is quite hard.)

Go Up