- #1
thedude36
- 30
- 0
I'm using arduino to make a water sensor. The sensor needs to go off after a certain period of time of not having come into contact with any water. The difficulty is that i can't use a delay() mechanism as it would mess with other functions of the sensor. I had thought i found a solution but i can't get it to work. what i came up with was
int seconds = 0;
long secPrev = 0;
long secInt = 1000;
void loop() {
∴long timer = millis();
∴if (timer - secPrev > 1000000) //to compensate for roll over
∴∴secPrev = 0;
∴if (timer - secPrev > secInt) { //should increment seconds by 1
∴∴seconds += 1;
∴∴secPrev = timer;
∴}
}
For some reason the seconds arent increasing. the secPrev value is behaving as it should, I am just not sure why the seconds arent. would anyone know why this is?
int seconds = 0;
long secPrev = 0;
long secInt = 1000;
void loop() {
∴long timer = millis();
∴if (timer - secPrev > 1000000) //to compensate for roll over
∴∴secPrev = 0;
∴if (timer - secPrev > secInt) { //should increment seconds by 1
∴∴seconds += 1;
∴∴secPrev = timer;
∴}
}
For some reason the seconds arent increasing. the secPrev value is behaving as it should, I am just not sure why the seconds arent. would anyone know why this is?