Joined: 25 May 2004 Posts: 190 Location: Ljubljana, Slovenia
Posted: Sun Feb 27, 2005 6:17 pm Post subject: Multipleclick on key
Doubleclick.
Everybody understands doubleclick on computer mouse. Something like that I am trying to achieve on my micro.
First I need a timing mashine to measure time delay in which the second click shoud reappear if doubleclick function is to be proccessed. So I start timer like this:
Code:
' 1 second = 1000000 usec = 32 (mod=0) x 250 (load timer) x 125 (Ticnt) ConfigTimer0=Timer , Gate=Internal , Mode=0 OnTimer0 Titi
LoadTimer0 , 250 EnableTimer0 StartTimer0 EnableInterrupts
So timerinterupts will apear 125 times in one second. I count them in Timer interrupt routine:
Code:
Titi: LoadTimer0 , 250 If Ticnt <255Then Incr Ticnt
End If
If Ticnt =50Then Set Clickflag 'set flag time interval elapsed Incr Ticnt 'to be sure, that clicflag set 'only ones for the time End If Return
As you can see, I count the interrupts only until the byte Ticnt is full ( 255) and when counter reaches no 50, I set a flag.
Everytime click appears, I reset counter Ticnt. If second click appear before Ticnt reaches 50, no Clickflag is set in the counter is set to zero again. Not before 50/125 second after last click the Clicflag is set.
Each click resets Ticnt and is registered in counter Clickcnt:
Code:
' somewhere in main program loop i test if key pressed: Debounce Key , 0 , Clicksr , Sub
Loop
Clicksr:
Ticnt =0 Incr Clickcnt
Return
I proccess the click in the main program loop after Clicflag is set:
Code:
' somewhere in main program loop If Clickflag =1Then Reset Clickflag
Cls
SelectCase Clickcnt
Case1:Lcd"Singleclick" Case2:Lcd"Doubleclick" Case3:Lcd"Tripleclick" CaseElseLcd"Multipleclick" Locate2 , 1 Lcd Clickcnt
EndSelect
Clickcnt =0'reset clickcounter End If
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum