Hey guys,
need help to debbounce an input by software. I just did it by hardware with a RC-module, calculated to 1ms but it doesn`t seem to be enough. I only analyze the state of a relay over an interrupt-input which is set to CHANGE. Every time I switch, a loop gets called.The MCU get disconnected from Blynk after a few switches. When I simulate it with a normal LED it works. So there must be a error with the relay toggle, that the loop Func_Raumlicht() gets called 1000-times.
I programmed at this way to realize a simple Zentral OFF function where I only have to call once the loop Raumlicht_ON_OFF()
Is there someone how can help me to implement also the software-solution Twice theimpact
Hey Martin, thanks for your answer. Now I edited the sketch above, so that you can comprehend my thinking. The loop Func_Raumlicht gets called every status change. It´s only here to
visualize the current state on Blynk App. When Raumlicht_ON_OFF gets called, a relay changes his current state (HIGH->LOW and LOW->HIGH). So that it works like this it´s necessary that it get called once. Else Func_Raumlicht() get called 1000-times and Blynk disconnects itself.
Maybe you could forget the interrupt, and go with a short timer? Then it would only check the relay once during that interval. (kind of like a debounce)
For example:
void setup() {
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode (WemosPin_D1, INPUT_PULLUP);
// Setup a function to be called every 100 ms
timer.setInterval(100L, Func_Raumlicht);
}
void Func_Raumlicht() {
Status_Raumlicht = digitalRead(WemosPin_D1);
if (Status_Raumlicht == 1) {
LED_Raumlicht.setColor (NEON_GREEN);
LED_Raumlicht.setValue (255);
Blynk.virtualWrite(V20, HIGH);
}
if (Status_Raumlicht == 0) {
LED_Raumlicht.off();
Blynk.virtualWrite(V20, LOW);
}
}
Hey Pete,
I think I have to disappoint you and your idea. First of all I would not use a periodically call of the input-state (so I don´t get any fade effects). To prevent that I had to program it with an “attachinterrupt” in setup. So that it would like seen like this
It’s just a standard renounce routine, it doesn’t matter if it’s called by polling with a timer it with an interrupt - I use it either way depending on what works best.
As I said earlier, there is in theory an issue with using millis() inside a function called by an interrupt, but in practice it works well.
If it’s not what you’re looking for then don’t use it.
It’s not me that will be disappointed
Sorry Pete that I called into question your kindly reply. I will try it tomorrow.
It was only my inner logic with wrote my last answer, and I never claimed that it´s usually right