picked up an uno kit to use for a project. i'm having some difficulty with the programming (total noob here...last time i coded was in basic) i have everything fleshed out on breadboard and everything works.
i managed to piece together some code and it almost does what I want... it looks right to me, but i've been staring at it so long i'm sure i'm looking past a glaring mistake. I think it's right, but it's wrong.
basically i'm lighting a "normal status" LED....monitoring the temp of a probe....when it reaches a set value, it should shut off the output of the normal status LED and turn on another output that is a "warning" LED.
as you will see below, I have the initalization of the normal status LED so it lights on startup... it switches the other LED on when the threshold is reached as intended, but does not turn off the normal status LED as intended...and does not turn off the warning LED once back below the threshold. my if else loop looks okay but is likely wrong.
i output the temp data to the serial port to confirm proper operation, this will be removed later.
any coders out there want a laugh?
unsigned long tepTimer ;
int ledred=9;
int lednorm=11;
void setup(){
Serial.begin(9600);
}
void loop(){
int val;
double data;
val=analogRead(0);
data = (double) val * (5/10.24); // convert the voltage to temperture
if(data>27){ // If the temperture is over 27 degrees then alarm
digitalWrite(ledred,HIGH);
digitalWrite(lednorm,LOW);
delay(2);
}
else { digitalWrite(ledred,LOW);
digitalWrite(lednorm,HIGH);
delay(2);}
if(millis() - tepTimer > 500){ // output the temperture value per 500ms
tepTimer = millis();
Serial.print(data);
}
}