I am a beginner in using Arduino and programming in c/c++. I am trying to connect a 10-segment LED and a moisture sensor to my Arduino Uno, and when the moisture level is very low, the first 2 red LEDs will be turned on, when it is slightly higher, the next three orange LEDs will be turned on, when it is slightly higher the next three green LEDs will be turned on, and finally when the moisture level is above the threshold for the green LEDs, the final blue LED segment will turn on.
I have written a program that works, and I have tested both the moisture sensor and the 10 segment LED separately to ensure they are working. Although the program works how I intend it, about 30-40% of the time I am unable to run the program due to an error message in the process of uploading. To be clear, I do not change the code at all from the working state of the code to the error message appearing. I wanted to know why this message appears, and how to avoid/resolve this issue.
I have included my code below:
/*
Arduino LED Bar Graph with Moisture Sensor
Started June 25, 2020
edited 6/28
(added blue LED)
*/
int redLED = 13;
int yellowLED = 12;
int greenLED = 11;
int blueLED = 10;
#define SensorPin A0
float sensorValue = 0;
float moistureLevel = 0;
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(redLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(blueLED, OUTPUT);
}
void loop()
{
if (Serial.available() > 900)
{
moistureLevel = Serial.read();//set the var moistureLevel
digitalWrite = (redLED, HIGH);
digitalWrite = (yellowLED, LOW);
digitalWrite = (greenLED, LOW);
digitalWrite = (blueLED, LOW)
}
else if (Serial.available() > 750)
{
moistureLevel = Serial.read();//set the var moistureLevel
digitalWrite = (yellowLED, HIGH);
digitalWrite = (redLED, LOW);
digitalWrite = (greenLED, LOW);
}
else(Serial.available() > 550)
{
moistureLevel = Serial.read();//set the var moistureLevel
digitalWrite = (greenLED, HIGH);
digitalWrite = (redLED, LOW);
digitalWrite = (yellowLED, LOW);
digitalWrite = (blueLED, LOW);
}
else(Serial.available() < 549)
{
moistureLevel = Serial.read();//set the var moistureLevel
digitalWrite = (greenLED, HIGH);
digitalWrite = (redLED, LOW);
digitalWrite = (yellowLED, LOW);
digitalWrite = (blueLED, HIGH);
}
for (int i = 0; i <= 100; i++)
{
sensorValue = sensorValue + analogRead(SensorPin);
delay(1);
}
sensorValue = sensorValue / 100.0;
Serial.println(sensorValue);
delay(100);
}
And here is a copy of the exact error message:
/tmp/777165248/sketch_jun25a/sketch_jun25a.ino: In function 'void loop()':
/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:33:33: error: assignment of function 'void digitalWrite(uint8_t, uint8_t)'
digitalWrite = {redLED, HIGH};
^
/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:33:33: error: cannot convert '<brace-enclosed initializer list>' to 'void(uint8_t, uint8_t) {aka void(unsigned char, unsigned char)}' in assignment
/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:34:35: error: assignment of function 'void digitalWrite(uint8_t, uint8_t)'
digitalWrite = (yellowLED, LOW);
^
/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:34:35: error: cannot convert 'int' to 'void(uint8_t, uint8_t) {aka void(unsigned char, unsigned char)}' in assignment
/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:35:34: error: assignment of function 'void digitalWrite(uint8_t, uint8_t)'
digitalWrite = (greenLED, LOW);
^
/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:35:34: error: cannot convert 'int' to 'void(uint8_t, uint8_t) {aka void(unsigned char, unsigned char)}' in assignment
/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:36:33: error: assignment of function 'void digitalWrite(uint8_t, uint8_t)'
digitalWrite = (blueLED, LOW)
^
/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:36:33: error: cannot convert 'int' to 'void(uint8_t, uint8_t) {aka void(unsigned char, unsigned char)}' in assignment
/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:41:36: error: assignment of function 'void digitalWrite(uint8_t, uint8_t)'
digitalWrite = (yellowLED, HIGH);
^
/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:41:36: error: cannot convert 'int' to 'void(uint8_t, uint8_t) {aka void(unsigned char, unsigned char)}' in assignment
/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:42:32: error: assignment of function 'void digitalWrite(uint8_t, uint8_t)'
digitalWrite = (redLED, LOW);
^
/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:42:32: error: cannot convert 'int' to 'void(uint8_t, uint8_t) {aka void(unsigned char, unsigned char)}' in assignment
/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:43:34: error: assignment of function 'void digitalWrite(uint8_t, uint8_t)'
digitalWrite = (greenLED, LOW);
^
/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:43:34: error: cannot convert 'int' to 'void(uint8_t, uint8_t) {aka void(unsigned char, unsigned char)}' in assignment
/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:47:3: error: expected ';' before '{' token
{
^
/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:54:3: error: 'else' without a previous 'if'
else(Serial.available() < 549)
^~~~
/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:55:3: error: expected ';' before '{' token
{
^
exit status 1
digitalWrite
command, to see if you made a mistake ... please do that