**Hi everyone,
I've built a panel that I want to use to turn a ventilation system on/off via a single-channel relay. It should also display temperature, humidity, etc. on a TFT ST7735. It either only turns the system on/off without the TFT display, or I only get the measured values without being able to activate the relay. I'm using an Arduino Uno, which is powered by a 5V power supply. Is this a programming error or is it a power supply issue?
Thanks a lot in advance, Thomas
**
You are right in principle, but I've focussed on displaying the status of the fan-motor on the TFT and put the sketch in. The wiring is very sensitive but is working.
Your button debouncing is flawed. So whatever anything else does is also.
Here's your code, stripped of the TFT stuff, with a real switch debounce code pattern substituted for what looked plausible. I know the method you were aiming for and as far as I can tell missed.
It is one of my least favorite patterns, so maybe I sabotaged it subconsciously, I don't think so.
In any case, mine works, so feel free to figure it out or work on testing (!) and fixing yours. Serial printing may help; I had quite a few print statements showing the flow through your code was bogus.
check the specification of your TFT ST7735 display - the UNO uses 5volt logic many TFT displays even though powered from 5V have an onboard 3.3V regulator and use 3.3V logic for its interface
if so the UNO/TFT interface requires level shifters or the TFT may be damaged
It functions by using a state variable which can be used as a "stable" value.
I don't like it, as I have said. One reason can be seen if you crank up the debounce time constant: the pushbutton action is not recognized and acted upon until it has been good and down for that period.
The I used algorithm in #5 acts as soon as it reads the button as different. After acting (or just ignoring the other edge) it does not look at the switch again for that same period. By the time it looks again, all bouncing is history.
Since switches do not show themselves as closed unless they are on their way to being fully closed and "stable", why not act then?
Similarly, switches do not show themselves as open unless they are on their way to being fully open and "stable".
If your switches do make little glitchy closures while no one is touching them, get better switches.
Other signals need different attention, as they may be noisy in a way that regular switches are not.
Some NC switches like window alarms might need the stabilising time to ride out brief open periods due to vibration.