Hi all
I have an issue which I cant seem to find why, I have a project which uses IF AND, the IF condition seems to work but the AND does not.
I post example code here
I set the count to 1, and read the temperature, if the temperature goes above the set limit and the count = 1 the led turns on for 5 seconds, then turns off, and that should be it, as the count is then set to 0, so the condition is never met again for the LED to turn on as the count remains 0.
However the code just carries on and cycles, turning the LED on and off as if the count did not matter.
A solution to this simple issue is much appreciated.
Cheers Alan
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS D5
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float temperature = 0;
int count = 1;
void setup(void)
{
pinMode(D2, OUTPUT);
Serial.begin(9600);
sensors.begin();
}
void loop(void)
{
sensors.requestTemperatures();
Serial.println(sensors.getTempCByIndex(0));
temperature = sensors.getTempCByIndex(0);
delay(1000);
if ((temperature > 28) && (count = 1)) {
digitalWrite(D2, HIGH);
delay(5000);
digitalWrite(D2, LOW);
count = 0;
}
}