Knowledge Base
Search and find technical support

[ADVANCED] Debounce on IO's

When working with divisible rooms and using a contact in the door/wall, it can in some cases be a good feature to add a delay to the input. Especially if you are using a page flip and executing sequences on "slow" products.

So in order to work around this you can add the script text as shown below and change the timings to suit your setup and so avoid pages flipping when contacts are in between positions.

Also find below the attached demo project, where you can see the script implemented.

 

In "Global variables" add this text:

The first three lines is where you change the variables, IOPIN, which serial number the IO is attached to, use 0 if attached to the main controller, and finally the delay you wish to use to create the best user experience.

mceclip0.png

#define IOPIN 1 //The number if the IO pin
#define IOPIN_UNITSN 0 //The SN number of the unit if not an extension set to 0
#define INPUT_DELAY 3 //Delay from input to action in sec


new uDelayCount = 0;
new uNewState = 0;
new uCountInProgress = false;
new tmpString[50] = "";

 

In "Global Functions" add the following

mceclip2.png

fnSendData(data[]){
//RS232Transmit(1, data, strlen(data));
}

 

In "I/O Control - IOPinChange" add the below text:

mceclip3.png

if(IOPin == IOPIN && UnitSN == IOPIN_UNITSN){
if(!uCountInProgress){
uNewState = NewState;
uCountInProgress = true;
uDelayCount = INPUT_DELAY;
strformat(tmpString, _, true , "Countdown start\r\n");
fnSendData(tmpString);
return;
}else if(uDelayCount){
return;
}
strformat(tmpString, _, true, "Execute IO pin change\r\n");
fnSendData(tmpString);
}

 

And finally add the following in "Timer1secEvent"

mceclip4.png

if(uDelayCount){
uDelayCount--;
strformat(tmpString, _, true, "Timer = %d\r\n", uDelayCount);
fnSendData(tmpString);
if(!uDelayCount){
new curpin = GetInputPin(1, 0);
strformat(tmpString, _, true, "Pin still change? %d = %d\r\n", uNewState, curpin);
fnSendData(tmpString);
if(uNewState == curpin){
@IOPinChange(IOPIN, uNewState, IOPIN_UNITSN);
}
uCountInProgress = false;
}
}

Was this article helpful?
2 out of 5 found this helpful