Hi,
When using Provisioning a briefly press of the button reset the settings. I understand that the button needs some sort of switch debouncer but if you have a look at the code, it shouldn’t be a problem:
void button_change(void)
{
#if BOARD_BUTTON_ACTIVE_LOW
g_buttonPressed = !digitalRead(BOARD_BUTTON_PIN);
#else
g_buttonPressed = digitalRead(BOARD_BUTTON_PIN);
#endif
if (g_buttonPressed) {
DEBUG_PRINT("Hold the button to reset configuration...");
g_buttonPressTime = millis();
DEBUG_PRINT("Button pressed");
DEBUG_PRINT(g_buttonPressTime);
} else {
uint32_t buttonHoldTime = millis() - g_buttonPressTime;
DEBUG_PRINT("Button time");
DEBUG_PRINT(buttonHoldTime);
if (buttonHoldTime >= BUTTON_HOLD_TIME_ACTION) {
button_action();
}
g_buttonPressTime = 4294967296;
}
}
void button_init()
{
#if BOARD_BUTTON_ACTIVE_LOW
pinMode(BOARD_BUTTON_PIN, INPUT_PULLUP);
#else
pinMode(BOARD_BUTTON_PIN, INPUT);
#endif
attachInterrupt(BOARD_BUTTON_PIN, button_change, CHANGE);
}
The serial monitor shows:
[13511] Hold the button to reset configuration...
[13518] Button pressed
[13530] 13517
[13725] Button time
[13725] 208
[13725] Button time
[13725] 13725
[13725] WAIT_CONFIG => RESET_CONFIG
As we saw on the serial monitor, the “Button time” is printed twice, but it doesn’t calculate the difference between millis()
on the second time. My only guess is that the button bounces too fast that mess with the calculation. Ideas?
Never Mind, removed capacitor and now is working… One of those things