local RC_OPTION = 300 local LED_PIN = 13 local NUM_LEDS = 12 local RUN_INTERVAL_MS = 1000 local BOOT_DELAY_MS = 5000 local MAV_SEVERITY_INFO = 6 local DEBUG = true local TUNE = 'MBT200>C#2A#2C#2A#2' local COLOR_ON = {255, 0, 0} local COLOR_OFF = {0, 0, 0} local COLOR_FLASH = { [true] = {255, 255, 255}, [false] = {0, 0, 0} } local RC_Chan = rc:find_channel_for_option(RC_OPTION) serialLED:set_num_neopixel(LED_PIN, NUM_LEDS) --"neopixel" for Matek-2812 using "12" LEDs. "profiled" might be your led type local flash_state = false local function set_leds(color) serialLED:set_RGB(LED_PIN, -1, table.unpack(color)) serialLED:send(LED_PIN) end local function do_transition(switch_position) if switch_position == 1 then if DEBUG then gcs:send_text(MAV_SEVERITY_INFO, 'LEDs: On') end set_leds(COLOR_ON) return do_leds end if switch_position == 2 then if DEBUG then gcs:send_text(MAV_SEVERITY_INFO, 'Buzzer: On') end return do_buzzer end if DEBUG then gcs:send_text(MAV_SEVERITY_INFO, 'LEDs/Buzzer: Standby') end set_leds(COLOR_OFF) return standby end function standby() local sw_pos = RC_Chan:get_aux_switch_pos() if sw_pos ~= 0 then return do_transition(sw_pos), 0 end return standby, RUN_INTERVAL_MS end function do_leds() local sw_pos = RC_Chan:get_aux_switch_pos() if sw_pos ~= 1 then return do_transition(sw_pos), 0 end return do_leds, RUN_INTERVAL_MS end function do_buzzer() local sw_pos = RC_Chan:get_aux_switch_pos() if sw_pos ~= 2 then return do_transition(sw_pos), 0 end notify:play_tune(TUNE) flash_state = not flash_state set_leds(COLOR_FLASH[flash_state]) return do_buzzer, RUN_INTERVAL_MS end gcs:send_text(MAV_SEVERITY_INFO, 'LED/Buzzer Script Active') return standby, BOOT_DELAY_MS