It goes to both interrupts setting high state on pin, but it's always high, event though there is digitalWrite(5,LOW) in second interrupt. I've checked this and it works:
void loop()
{
digitalWrite(5,HIGH);
delay(1000); //works fine
digitalWrite(5,LOW);
delay(1000)
}
Well I also would like to add sending data via Bluetooth so I guess I can't use delay() to not block ESP. I would like to just have cyclic Turn on-> wait some time-> turn off etc. Don't know if my solution is right.
I wouldn't use delay either..
you're duration is quite large, can easily track this using a millis timer and state machine ..
won't slow the loop down at all and no complexity..
Yes, please if it's not the problem. The timers I used was something I first saw and tried to use them. And I tought interrupts will be good when also bluetooth transmission is present.
#define PUMP_PIN 5
#define MINS 1000 * 60
unsigned long lastPump;
unsigned long intervalPump = 5 * MINS;
bool pumpOn = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(PUMP_PIN, OUTPUT);
}
void loop() {
CheckPump();
}
void CheckPump() {
unsigned long now = millis();
if (now - lastPump >= intervalPump) {
lastPump = now;
if (!pumpOn) {
//turning pump on
Serial.println("Pump On");
digitalWrite(PUMP_PIN, HIGH);
//set new interval 15 minutes..
intervalPump = 15 * MINS;
pumpOn = true;
} else {
//turning pump off
Serial.println("Pump Off");
digitalWrite(PUMP_PIN, LOW);
//set new interval 5 mins..
intervalPump = 5 * MINS;
pumpOn = false;
}
}
}
no timers needed..
takes 5 minutes before pump starts..
could initially set the intervalPump to 0 and it would turn on at boot..
keep your loop fast, avoid delay..
Yes..
The first example uses the loop..
The second example is just putting the routine into its own thread..
So far as everything sits now, I would use the loop, less complex..