Timer with adjustable speed based on touch "move" event

Hi,

I am able to make a button which when it is touched, a timer will start counting up. 

I use timer.performWithDelay to call a function which it will perform an increment.

When touch is “ended”. the timer will stop. I use timer.cancel.

Now I want to make something extra:

When touched, the timer will count at a speed of, for example, an increment of 1 every 0.1 seconds. (timeDelay = 100)

When event is “moved” up, the timer will count at increased speed. The more you move up your fingers, the faster the timer will count.

When “moved” back down, the speed of the timer counts will decrease.

When touch is “ended”. the timer will stop. 

The next touch event, the timer speed will be reset back to the default. (which is increment of 1 every 0.1 seconds).

How do I do that?

I tried to obtain the distance between the initial touch event.y and the current event.y, then I divide it by display.contentHeight and I will get a number between 0 & 1. Then I multiply the “timeDelay” with the figure.

local a = t.y0 - event.y – this will get me the distance of my finger moved from the initial touch position.

local b = a / display.contentHeight – this will get me a value between 0 & 1

timeDelay = timeDelay * b – this will give me a lower value of timeDelay

However, the timer.performWithDelay is still using the original value of the timeDelay, which is 100. 

It wouldn’t update to the latest value of the timeDelay.

Should I use onEnterFrame to perform the increment task instead of timer.performWithDelay?

Thanks

Chong