I Want to build a timer function that clicking will add a few seconds

I Want to build a timer function that clicking will add a few seconds if the function is already working and clicked again it will add time to existing function. And not called her again at the same time
I tried to work if a recursive function that attempts to persuade him at but it is possible

`local cycles=0;
function pin7changed() {
// declare a local variable - we can store the value of the pin in here if we need it
local buttonState = hardware.pin7.read();

// if buttonState is 0, the button is pushed
if (buttonState == 1) {
    // server.show logs text to the logs, but also displays text right in the node on the planner
    server.log("Button Pressed!");
    cycles+=30
    timer();
    
    
} else {
    server.log("Button Released!");
}

}

// configure the imp’s hardware
// pin 7 is a digital input (0 or 1) and is pulled up externally
hardware.pin7.configure(DIGITAL_IN_PULLUP, pin7changed);

function timer() {
cycles–;
if (cycles) imp.wakeup(1, function() { timer(cycles) } );
server.log("timer "+cycles);
}
`

One problem is that you start off a brand new timer every time buttonState is 1, whereas what you actually want to do is start the timer only if it wasn’t already started:
if (buttonState == 1) { if (cycles) { cycles += 30; } else { cycles = 30; timer(); } }

Peter

It does not work
`local cycles=0;
function pin7changed() {
// declare a local variable - we can store the value of the pin in here if we need it
local buttonState = hardware.pin7.read();

if (buttonState == 1)
{
if (cycles)
{
cycles += 30;
}
else
{
cycles = 30;
timer();
}
}

}

// configure the imp’s hardware
// pin 7 is a digital input (0 or 1) and is pulled up externally
hardware.pin7.configure(DIGITAL_IN_PULLUP, pin7changed);

function timer() {
cycles–;
if (cycles) imp.wakeup(1, function() { timer(cycles) } );
server.log("timer "+cycles);
}
`

יום שלישי 16 אפריל 2013 13:33:09: Device configured to be "Hello World Program"
יום שלישי 16 אפריל 2013 13:34:59: timer 29
יום שלישי 16 אפריל 2013 13:35:00: ERROR: wrong number of parameters
יום שלישי 16 אפריל 2013 13:35:00: ERROR: at unknown:33
יום שלישי 16 אפריל 2013 13:35:05: Power state: online=>offline
יום שלישי 16 אפריל 2013 13:35:06: Power state: offline=>online
יום שלישי 16 אפריל 2013 13:35:06: Device booting
יום שלישי 16 אפריל 2013 13:35:06: Device configured to be “Hello World Program”

How many parameters does the function timer() take? How many are being passed to it, on line 33?

Peter

This line 33:
hardware.pin7.configure(DIGITAL_IN_PULLUP, pin7changed);

By the way thanks for the help