Does that "else" look like any other "else" in examples you've come across?
hi awal,
yes i had already worked it out my program has now "compiled" and working was just trying to work out how use tags when posting code
thanks very much for your help, wish i had started to learn programming years ago, its just so nteresting love it.
/*
* 2 switches monitoring two fans, healthly if both switches are low output switches a relay, if any input high an alarm sounds no output to relay.
*/
int greenled = 9; // green led lights if fan1 and fan2 are low connected to pin 9. (operates a relay)
int redled = 8; // red led lights if fan 1 or fan2 are high connected to pin 8. (sounds an alarm)
int fan1 = 3; // fan switch is connected to pin 3
int fan2 = 2; // fan switch is connected to pin 2
int fan1val; // variable for reading the pin status
int fan2val; // variable for reading the pin status
void setup(){
pinMode(greenled, OUTPUT); // Set the Greenlled pin as output-- this will light up if i get a low at fan1+fan2
pinMode(redled, OUTPUT); // Set the LED pin as output-- this will light up if i get a low at fan1+fan2
pinMode(fan1, INPUT); // Set the switch pin as input
pinMode(fan2, INPUT); // Set the switch pin as input
}
void loop(){
fan1val = digitalRead(fan1); // read input value and store it in val
fan2val = digitalRead(fan2); // read input value and store it in val
if (fan1val == LOW && fan2val == LOW) { // check if both inputs show fan OK (Switch is pressed)
digitalWrite(greenled, HIGH); // turn green on
digitalWrite(redled, LOW); // .. and red off red*** RED DOES NOT TURN OFF, IT STAYS ON ALL THE TIME.
} else; // we do not need to test the opposite - we do not light green, we light red
digitalWrite(greenled, LOW); // turn green OFF ***does turn off***
digitalWrite(redled, HIGH); // .. and red on **** is Red**
}
there seems to be an error with the red led as it stays on all the time, i have tripple checked my circuit im getting the correct inputs two lows, the redled should turn off, it stays on all the time? any ideas?
thanks
i have tripple checked my circuit im getting the correct inputs two lows
How do you KNOW this? There are no Serial.print() statements in your code.
} else; // we do not need to test the opposite - we do not light green, we light red
What do you supposed that ; there does? Not what you think would be my guess.
i know this because im not using a serial monitor, ive got it in a circuit switching 0v into pins 2 and 3, and leds on 8,9.
ok now sorted missing { should be ..... } else {
i sort of understand the statment if (fan1val == LOW && fan2val == LOW) do this
"else"
do this other function..
thanks for the help and everybody patience