Hi,
You need to restructure you code so that at the start of the void loop(), you read ALL your inputs and assign the values to variables, then ONLY use those variable through the rest of you code.
The values being up dated each time the code loops back to the start.
For example;
switchState = digitalRead(switchPin);
sensorVal = analogRead(sensorPin);
// instead of
// if (analogRead(switchpin) == LOW && analogRead(sensorpin) <= || == 499) {
if (switchState == LOW && sensorVal <= 499) {
// which says.. if switchState is LOW AND sensorVal is LESS THAN OR EQUAL To 499.
}
analogReading each time that you need the value makes reading your code cumbersome, and not needed because of the speed of the loop.
In fact doing repeated unnecessary analogRead will probably slow the loop down.
So read ALL your variables and assign their values to meaningfull variable names at the start of the loop.
Then use the variables when you do tests. ![]()
Did you read the link, look at operators.
Tom... ![]()