Button shutdown timer with NTC 10k plugged

After testing some of the features i find that the code for the button timer is not correct when the ntc 10k thermistors are plugged in .
The bms does not shutdown gracefully and this shifts the oled screen upward. Some text for the top appears at the bottom and the text from the middle of the screen is now at the top .
This happens when the user presses the power button for the 3 seconds to shutdown the bms gracefully . However because the Ntc is plugged in the button press requires a delay timer which im not sure how to impliment .

  // shutdown BMS if button is pressed > 3 seconds
        if (button == 1) {
            if (btnTimer.read() > 3) {
                BMS.shutdown();                                ///// Timer required after this line 
        } else {

This should prevent the screen from flickering off then on again quickly and shifting text upward.

Please advise the correct way of adding a delay as my skills are limted but delay(10000); doesnt work as its needing a definition. maybe not the correct way ? 10s delay to ignore the button press after being pressed is key to ensuring a quick reboot doesnt occur when shutting down.

There is no delay() in mbed, you have to use wait ().

But I can’t see the point of introducing a delay here. The controller will not execute your delay code when it is switched off :wink:

IMHO this might be a bouncing issue.

It might be a problem of the cheap OLED display. After restart, I also get shifts of the lines in the OLED roughly 1 out of 10 times. But it’s not caused by the BMS, it happens also in the MPPT.

thank you for that i was presuming that this might be the case . However with regards to the shutdown . if i dont time the release of the button correctly then the bms will cycle down and power on in the very second after shutting down . im not sure what causes this .

Good day, is there any way to prevent the bounce issues from occuring on the power button .

You could try to place a wait(2) command between
if (btnTimer.read() > 3) {
This way the button is no more pressed when the BMS goes into shutdown.

Detection of shutdown command could be signalled via LED blinking for example.

100% this has solved the issue no bounce at least once the screen is off the user still has some time to let go of the power button with in a reasonable time . Thank you very much

The idea was to let go the button when the shutdown is triggered but before the BMS switches off (press longer than 3s but shorter than 5s).