Pages: [1]   Go Down
Author Topic: Ivalue required as left operand of assignment error  (Read 1347 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
120 -= 20

You can't subtract a constant from another constant.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Germany
Offline Offline
Faraday Member
**
Karma: 56
Posts: 2983
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6132
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  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:
for (int i=120; i > 0; i = i-20) {


http://arduino.cc/en/Reference/For
« Last Edit: May 06, 2012, 02:07:15 pm by James C4S » Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: