I’m getting this error message and I don’t understand what it’s trying to say.
Arduino: 1.8.1 (Windows 10), Board: "Arduino/Genuino Uno"
C:\Users\kabir\Documents\Arduino\PROTOTYPE\PROTOTYPE.ino: In function 'void loop()':
PROTOTYPE:62: error: lvalue required as left operand of assignment
if (sensorValue0 < 200 && sensorValue1 < 200 && servoPosition = initial && servoPosition2 = initial) {
^
exit status 1
lvalue required as left operand of assignment
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Here my full code:
#include <Servo.h>
//MOTOR1
Servo Motor;
int servoPosition = 10;// the current angle of the servo - starting at 90.
int servoSlowInterval = 80; // millisecs between servo moves
int servoFastInterval = 100;
int servoInterval = servoSlowInterval; // initial millisecs between servo moves
int servoDegrees = 5;// amount servo moves at each step
const int servoPin = 9; // the pin number for the servo signal
const int servoMinDegrees = 5; // the limits to servo movement
const int servoMaxDegrees = 15;//Increase to increase servo ON time
unsigned long previousServoMillis = 0; // the time when the servo was last moved
unsigned long currentMillis = 0;
//MOTOR2
Servo Motor2;
int servoPosition2 = 10;// the current angle of the servo - starting at 90.
int servoSlowInterval2 = 80; // millisecs between servo moves
int servoFastInterval2 = 100;
int servoInterval2 = servoSlowInterval2; // initial millisecs between servo moves
int servoDegrees2 = -5;// amount servo moves at each step
const int servoPin2 = 10; // the pin number for the servo signal
const int servoMinDegrees2 = 5; // the limits to servo movement
const int servoMaxDegrees2 = 15;//Increase to increase servo ON time
unsigned long previousServoMillis2 = 0; // the time when the servo was last moved
unsigned long currentMillis2 = 0;
//LDRS
int sensorPin0 = A0; // select the input pin for ldr
int sensorValue0 = 0; // variable to store the value coming from the sensor
int sensorPin1 = A1;
int sensorValue1 = 0;
int sensorPin2 = A2;
int sensorValue2 = 0;
int sensorPin3 = A3;
int sensorValue3 = 0;
void setup() {
Serial.begin(9600); //sets serial port for communication
Motor.write(servoPosition); // sets the initial position
Motor.attach(servoPin);
Motor2.write(servoPosition);
Motor2.attach(servoPin2);
}
void loop() {
sensorValue0 = analogRead(sensorPin0); // read the value from the sensor
Serial.println(sensorValue0); //prints the values coming from the sensor on the screen
delay(500);
sensorValue1 = analogRead(sensorPin1); // read the value from the sensor
Serial.println(sensorValue1);
delay(500);
sensorValue2 = analogRead(sensorPin2); // read the value from the sensor
Serial.println(sensorValue2);
delay(500);
sensorValue3 = analogRead(sensorPin3); // read the value from the sensor
Serial.println(sensorValue3);
delay(500);
//END_LDR_SETUP//////
if (sensorValue0 < 200 && sensorValue1 < 200 && servoPosition = 10 && servoPosition2 = 10) {
pinMode(servoPin, HIGH);
pinMode(servoPin2, HIGH);
currentMillis = millis();
servoSweep();
currentMillis = millis();
servoSweep2();
} else {
pinMode(servoPin, LOW);
pinMode(servoPin2, LOW);
}
if (sensorValue2 > 300 && sensorValue3 > 300 && servoPosition < servoMaxDegrees && servoPosition2 < servoMinDegrees2) {
pinMode(servoPin, HIGH);
pinMode(servoPin2, HIGH);
currentMillis = millis();
servoSweep_();
currentMillis = millis();
servoSweep_2();
} else {
pinMode(servoPin, LOW);
pinMode(servoPin2, LOW);
}
}
void servoSweep() {
// this is similar to the servo sweep example except that it uses millis() rather than delay()
// nothing happens unless the interval has expired
// the value of currentMillis was set in loop()
if (currentMillis - previousServoMillis >= servoInterval) {
// its time for another move
previousServoMillis += servoInterval;
servoPosition = servoPosition + servoDegrees; // servoDegrees might be negative
if (servoPosition <= servoMinDegrees) {
// when the servo gets to its minimum position change the interval to change the speed
if (servoInterval == servoSlowInterval) {
servoInterval = servoFastInterval;
}
else {
servoInterval = servoSlowInterval;
}
}
if ((servoPosition >= servoMaxDegrees) || (servoPosition <= servoMinDegrees)) {
pinMode (servoPin, LOW);
}
// make the servo move to the next position
Motor.write(servoPosition);
// and record the time when the move happened
}
}
void servoSweep2() {
// this is similar to the servo sweep example except that it uses millis() rather than delay()
// nothing happens unless the interval has expired
// the value of currentMillis was set in loop()
if (currentMillis2 - previousServoMillis2 >= servoInterval2) {
// its time for another move
previousServoMillis2 += servoInterval2;
servoPosition2 = servoPosition2 + servoDegrees2; // servoDegrees might be negative
if (servoPosition2 <= servoMinDegrees2) {
// when the servo gets to its minimum position change the interval to change the speed
if (servoInterval2== servoSlowInterval2) {
servoInterval2 = servoFastInterval2;
}
else {
servoInterval2= servoSlowInterval2;
}
}
if ((servoPosition2 >= servoMaxDegrees2) || (servoPosition2 <= servoMinDegrees2)) {
pinMode(servoPin2, LOW);
}
// make the servo move to the next position
Motor2.write(servoPosition2);
// and record the time when the move happened
}
}
void servoSweep_() {
// this is similar to the servo sweep example except that it uses millis() rather than delay()
// nothing happens unless the interval has expired
// the value of currentMillis was set in loop()
if (currentMillis - previousServoMillis >= servoInterval) {
// its time for another move
previousServoMillis += servoInterval;
servoPosition = servoPosition - servoDegrees; // servoDegrees might be negative
if (servoPosition <= servoMinDegrees) {
// when the servo gets to its minimum position change the interval to change the speed
if (servoInterval == servoSlowInterval) {
servoInterval = servoFastInterval;
}
else {
servoInterval = servoSlowInterval;
}
}
if ((servoPosition >= servoMaxDegrees) || (servoPosition <= servoMinDegrees)) {
pinMode(servoPin, LOW);
}
// make the servo move to the next position
Motor.write(servoPosition);
// and record the time when the move happened
}
}
void servoSweep_2() {
// this is similar to the servo sweep example except that it uses millis() rather than delay()
// nothing happens unless the interval has expired
// the value of currentMillis was set in loop()
if (currentMillis2 - previousServoMillis2 >= servoInterval2) {
// its time for another move
previousServoMillis2 += servoInterval2;
servoPosition2 = servoPosition2 - servoDegrees2; // servoDegrees might be negative
if (servoPosition2 <= servoMinDegrees2) {
// when the servo gets to its minimum position change the interval to change the speed
if (servoInterval2== servoSlowInterval2) {
servoInterval2 = servoFastInterval2;
}
else {
servoInterval2= servoSlowInterval2;
}
}
if ((servoPosition2 >= servoMaxDegrees2) || (servoPosition2 <= servoMinDegrees2)) {
pinMode(servoPin2, LOW);
}
// make the servo move to the next position
Motor2.write(servoPosition2);
// and record the time when the move happened
}
}
//////END_PROTOTYPE/////////////
Thanks.