I am changing code from an application using an arduino pro mini 3.3v with HC12 wireless module to
an ESP32 with integrated wifi and bluetooth (ESP32 devkit 1)
I didn't get this error before with similar code for the arduino pro mini module and HC12 module.
However now that I compile it I am getting this error
lvalue required as left operand of assignment error
I found this link to get some clarity on the issue.
However, I don't think I'm making the error mentioned in the link above.
Can someone please explain what I may be doing wrong? Thanks.
I get the error around this line of code: "BR = constrain(BR, 0, 510)"
This portion of code is being used to calibrate photoresistor sensors to report similar values despite
their inherent variances due to manufacturing tolerances, etc...
//Special thanks to geobruce at instructables.com
//Special thanks to Robin2 and his code for parsing data, and others on arduino forums
//Special thanks to Ahmet Burkay Kirnik for his code for Measure Angle with a MPU-6050(GY-521)
#include<Wire.h>
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
const int MPU_addr = 0x68;
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;
int minVal = 85;
int maxVal = 402;
double x;
int EA; //elevation angle
double z;
const int sensorPinTL = 33; //top left sensor pin
const int sensorPinBL = 35;
const int sensorPinTR = 32;
const int sensorPinBR = 34;
// The sensor value
int TL = 0;
int BL = 0;
int TR = 0;
int BR = 0;
// As photoresistor approaches minimum sensor value more light is seen by it
int sensorMinTL = 0;
int sensorMinBL = 0;
int sensorMinTR = 0;
int sensorMinBR = 0;
int sensorMaxTL = 4096;
int sensorMaxBL = 4096;
int sensorMaxTR = 4096;
int sensorMaxBR = 4096;
void setup() {
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
Serial.begin(115200);
SerialBT.begin("ESP32TransmitST");
}
void loop() {
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr, 14, true);
AcX = Wire.read() << 8 | Wire.read();
AcY = Wire.read() << 8 | Wire.read();
AcZ = Wire.read() << 8 | Wire.read();
int xAng = map(AcX, minVal, maxVal, -180, 180);
int yAng = map(AcY, minVal, maxVal, -180, 180);
int zAng = map(AcZ, minVal, maxVal, -180, 180);
EA = RAD_TO_DEG * (atan2(xAng, zAng));
// Calibrate during the first five seconds
while (millis() < 5000) {
TL = analogRead(sensorPinTL);
BL = analogRead(sensorPinBL);
TR = analogRead(sensorPinTR);
BR = analogRead(sensorPinBR);
// Record the maximum sensor value
if (TL > sensorMaxTL) {
sensorMaxTL = TL;
}
if (BL > sensorMaxBL) {
sensorMaxBL = BL;
}
if (TR > sensorMaxTR) {
sensorMaxTR = TR;
}
if (BR > sensorMaxBR) {
sensorMaxBR = BR;
}
if (TL < sensorMinTR) {
sensorMinTR = TL;
}
if (BL < sensorMinTR) {
sensorMinTR = BL;
}
if (TR < sensorMinTR) {
sensorMinTR = TR;
}
if (BR < sensorMinTR) {
sensorMinTR = BR;
}
}
// Signal the end of the calibration period
// Read the sensor
TL = analogRead(sensorPinTL); // Top left sensor
BL = analogRead(sensorPinBL); // Bottom left sensor
TR = analogRead(sensorPinTR); // Top right sensor
BR = analogRead(sensorPinBR); // Bottom right sensor
// Apply the calibration to the sensor reading
TL = map(TL, sensorMinTL, sensorMaxTL, 0, 510);
BL = map(BL, sensorMinBL, sensorMaxBL, 0, 510);
TR = map(TR, sensorMinTR, sensorMaxTR, 0, 510);
BR = map(BR, sensorMinBR, sensorMaxBR, 0, 510);
// In case the sensor value is outside the range seen during calibration
TL = constrain(TL, 0, 510);
BL = constrain(BL, 0, 510);
TR = constrain(TR, 0, 510);
BR = constrain(BR, 0, 510);
//Sends analog values in this format: i.e. <380,148,224,260,45>
Serial.print("<");
Serial.print(TL);
Serial.print(",");
Serial.print(BL);
Serial.print(",");
Serial.print(TR);
Serial.print(",");
Serial.print(BR);
Serial.print(",");
Serial.print(EA);
Serial.print(">");
Serial.println();
SerialBT.print("<");
SerialBT.print(TL);
SerialBT.print(",");
SerialBT.print(BL);
SerialBT.print(",");
SerialBT.print(TR);
SerialBT.print(",");
SerialBT.print(BR);
SerialBT.print(",");
SerialBT.print(EA);
SerialBT.print(">");
SerialBT.println();
delay(400);
}