I seem to have figured it out! All I needed was to add a "break" to my code and now it's doing exactly what I want it to. However, I've ran into this one issue.
If I leave a conditional statement for the lux as below:
while (system1state == "on"){
if (lux > 70) {
value = 70;
warningstate = "Message: System will adjust lighting output to day-time conditions.";
digitalWrite(redled, LOW);
digitalWrite(yellowled, LOW);
digitalWrite(greenled, HIGH);
}
if (lux < 5 && lux >= 0) {
value = 0;
warningstate = "Message: System will turn lights off due to night-time conditions.";
digitalWrite(redled, LOW);
digitalWrite(yellowled, HIGH);
digitalWrite(greenled, LOW);
}
if (lux = -1) {
value = -1;
warningstate = "Check sensor.";
digitalWrite(redled, HIGH);
digitalWrite(yellowled, LOW);
digitalWrite(greenled, LOW);
}
else if (lux > 5 && lux <70) {
warningstate = "Message: System will dim lights due to minimal environmental light.";
digitalWrite(redled, LOW);
digitalWrite(yellowled, LOW);
digitalWrite(greenled, HIGH);
}
value = lux;
value = constrain(value, 0, 70);
value = map(value, 0, 70, 0, 255);
analogWrite(system1, value);
// Break
break;
}
while (system2state == "on"){
if (lux > 70) {
value = 70;
warningstate = "Message: System will adjust lighting output to day-time conditions.";
digitalWrite(redled, LOW);
digitalWrite(yellowled, LOW);
digitalWrite(greenled, HIGH);
}
if (lux = -1) {
value = -1;
warningstate = "Check sensor.";
digitalWrite(redled, HIGH);
digitalWrite(yellowled, LOW);
digitalWrite(greenled, LOW);
}
if (lux < 5 && lux >= 0) {
value = 0;
warningstate = "Message: System will turn lights off due to night-time conditions.";
digitalWrite(redled, LOW);
digitalWrite(yellowled, HIGH);
digitalWrite(greenled, LOW);
}
else if (lux > 5 && lux <70) {
warningstate = "Message: System will dim lights due to minimal environmental light.";
digitalWrite(redled, LOW);
digitalWrite(yellowled, LOW);
digitalWrite(greenled, HIGH);
}
value = lux;
value = constrain(value, 0, 70);
value = map(value, 0, 70, 0, 255);
analogWrite(system2, value);
// Break
break;
}
if (system1state == "off"){
if (system1state == system2state) {
warningstate = "System is off.";
digitalWrite(redled, HIGH);
digitalWrite(yellowled, LOW);
digitalWrite(greenled, LOW);
}
}
if (system2state == "off"){
if (system2state == system1state) {
warningstate = "System is off.";
digitalWrite(redled, HIGH);
digitalWrite(yellowled, LOW);
digitalWrite(greenled, LOW);
}
}
I get a return of:
lux: -1
"Check sensor."
Even though the conditions aren't met.
4112021.ino (11.8 KB)