Issues with Timers

I’m trying to program in a timer that sets switches to off. I can get the timers to work but I would like the timers to be canceled or reset every time a switch is used. My code is below.

 

 

timer1 = “off”

function onSwitchPress( event )

switch = event.target
if timer1 == “running” then
timer.cancel ( event.countdown )

else

function countdown( event )

timer1 = “running”
EXSelect:setState( {isOn = false } )
PDSelect:setState( {isOn = false } )
P1Select:setState( {isOn = false } )
P2Select:setState( {isOn = false } )
P3Select:setState( {isOn = false } )
P4Select:setState( {isOn = false } )

end
end

timer.performWithDelay( 3000, countdown)

end

So for example something like 

NOTE - true equals "on". if switch == true then timer.cancel end

–SonicX278 

So for example something like 

NOTE - true equals "on". if switch == true then timer.cancel end

–SonicX278