Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

touch screen button debouncing

Status
Not open for further replies.

drkidd22

Member
Hello,

I have a program up and running and displaying a button on the touch screen, but I'm having some issues trying to get turn the LED on/off with the button. Basically one press should turn the led on and the second press turn it off assuming it's initialy off. Below is the code, I tried doing different configurations, but I think I might be having some denouncing issues as the led sometimes blinks and turns on and stays on.

Code:
#include "main_BasicLCDsetup.h" 
#include "GDD_Screens.h"
#include "periphDev.h"

extern float voltage_x1000;

// Configuration bits
_CONFIG2(FNOSC_PRI & POSCMOD_XT & IESO_ON & FCKSM_CSDCMD & OSCIOFNC_OFF) // Primary XT OSC with PLL
_CONFIG1(JTAGEN_OFF & FWDTEN_OFF & GCP_OFF & BKBUG_OFF & COE_OFF & ICS_PGx2 & WINDIS_OFF)   // JTAG off, watchdog timer off

WORD    	updateBTN1 = 0;

int main(void){

int	BTN1st = 0;
	EEPROMInit();   					// initialize EEPROM
    TouchInit();    					// initialize touch screen
	GOLInit(); // initialize graphics library &

if(GRAPHICS_LIBRARY_VERSION != EEPROMReadWord(EEPROM_VERSION)){
        TouchCalibration();
        TouchStoreCalibration();
        EEPROMWriteWord(GRAPHICS_LIBRARY_VERSION,EEPROM_VERSION);
    }

 TouchLoadCalibration();

char val[10]; 
double voltAVG;
int i;

GOL_MSG msg; // GOL message structure to interact with GOL


/****************************************************************
Initialize the main screen created with Graphips Display Designer
this function resides in the GDD_Screens.c file which is automatically
generated by the designer.
*****************************************************************/

CreatemainScrn(); 
//initADC (ADCIN);

while(1)
{
        if (GOLDraw()) {				// Draw GOL object
        	TouchGetMsg(&msg);   		// Get message from touch screen
        	GOLMsg(&msg);        		// Process message
        }

[COLOR="red"]if (updateBTN1 && !BTN1st)  //This is where I'm having problems
	{	
		__delay_ms(20);
		TRISDbits.TRISD3 = 0;
		LATDbits.LATD3 = 1;
		BTN1st = 1;
}

else if (updateBTN1 && BTN1st)
	{	
		__delay_ms(20);
		TRISDbits.TRISD3 = 0;
		LATDbits.LATD3 = 0;
}

}
WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg){
WORD objectID;
objectID = GetObjID(pObj);

if (objectID == mainScrn_BTN1) {
		if (objMsg == BTN_MSG_PRESSED) // check if button is pressed

{
    			updateBTN1 = 1;
}
				}					
return 1;
}	
[/COLOR]
WORD GOLDrawCallback(){
    return 1;
}

Any help will be appreciated. I think it would be the same idea if a mechanical switch was being used, but I have not been able to accomplish that either.
 
After you get a touch screen press ignore the display for a period of time. I would start with 1 second and decrease the time to the point where the action feels natural.

If you do not get any false triggering you are done.
 
20ms..... Think of the user... I know that 20ms is approximately how long bounce can be... But you have to be realistic. When I poll a button I try to use 250 - 300ms for a sounder to beep, even this is quite fast in human terms.

Ian
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top