Evo teksta / simulacije koji sam sebi napravio da bih skapirao problem ali mi ne ide a vama ce pojasniti sta zelim.
temp – Temperatura koju ocitava senzor
tempState – Trenutna ocitana temperatura
lasttempState = 99
tempState = temp; -------- Inicijalnoo citanje temperature npr. 24
if (lasttempState > tempState);-------- prvi krug - lasttempState je 99 a tepmeratura je 24 (99>=24)
lasttempState = tempState; ------------ uslov je ispunjen i lasttempState postaje 24
Serial.println("Min T: "); ----------------- ispisuje na displeju:
Serial.println(lasttempState); ----------- Min T: 24
if (lasttempState > tempState);-------- drugi krug - ocitavanja tepmeratura je i dalje 24 (24 = 24 )
lasttempState = tempState; ------------ lasttempState ostaje 24 jer uslov nije ispunjen
Serial.println("Min T: "); ----------------- ispisuje na displeju:
Serial.println(lasttempState); ----------- Min T: 24
if (lasttempState > tempState); --------- u trecem krugu ocitavanja - tepmeratura je porasla na 26
lasttempState = tempState;-------------- lasttempState ostaje 24 posto je 24 manje od 26 i uslov nije ispunjen
Serial.println("Min T: ");------------------ ispisuje na displeju:
Serial.println(lasttempState);------------ Min T: 24
if (lasttempState > tempState);-------- u cetvrti krugu ocitavanja - temperatura je pala i sada je 22 (24 > 22)
lasttempState = tempState;------------- uslov je ispunjen i lasttempState postaje 22
Serial.println("Min T: ");----------------- ispisuje na displeju:
Serial.println(lasttempState); ----------- Min T: 22
ITD....
Ma koliko ovo meni delovalo logicno i ok "Min T" je uvek jednaka trenutnoj i ja ne znam da resim ovo...
Evo i koda:
int sensePin = A0; //This is the Arduino Pin that will read the sensor output
int sensorInput; //The variable we will use to store the sensor input
double temp; //The variable we will use to store temperature in degrees.
int lasttempState =0;
int tempState = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
sensorInput = analogRead(A0); //read the analog sensor and store it
temp = (double)sensorInput / 1024; //find percentage of input reading
temp = temp * 5; //multiply by 5V to get voltage
temp = temp - 0.5; //Subtract the offset
temp = temp * 100; //Convert to degrees
Serial.print("Current Temperature: ");
Serial.println(temp);
tempState = temp;
if (lasttempState > tempState);
lasttempState = tempState;
Serial.print("Min T: ");
Serial.println(lasttempState);
delay(1000);
}
Unapred se zahvaljujem svima na pomoci