The code either flashes continuously the led and sound if switch is set to ON, or it launches the selftest sequence if the switch is brought back to ARM within 1 second after being set to ON (as per the manual)
Notice the use of hw_switch_add() here
Code: Select all
-- Load sound
Beep = sound_add("beep.wav")
-- Add LED, extinguished
LED = hw_output_add("ELT LED", false)
------------------ blinking state when ON -----------------
blink=true -- status of the led (ON or off)
beep_is_on=false -- state of the beacon
function blink_callback()
blink=not(blink) -- every time the function is called the state of the LED is changed
if beep_is_on then
hw_output_set(LED, blink)
sound_play(Beep)
else
hw_output_set(LED, false)
sound_stop(Beep)
end
end
tmr_blink=timer_start(0,250,blink_callback) -- always on timer for blinking sequence
-------------------------self test sequence if switch ON then OFF under 1 sec-----------
function self_test()
test=false
if beep_is_on==false then -- the switch has been brought to ARM, we initiate the self test sequence
print("test")
timer_start(0,1000,4, function()
test=not(test)
hw_output_set(LED, test) -- alternates ON/OFF 4 times within 4 seconds (two seconds total)
if test then
sound_stop(Beep)
sound_play(Beep)
end
end) -- timer
end
end
function input_change (state)
print(state)
if state == 1 then-- Switch moved to "On"
beep_is_on=true -- we start blinking and sound
timer_start(1000,self_test) -- we check after 1 second whether the switch is back to ARM (beep is --> self test sequence
else -- The switch is back to ARM
beep_is_on=false
end
end
inp_id = hw_switch_add("ELT Switch", 2,input_change)