Hello everyone, migrating from inav to my new ardupilot wing i was trying to set up a single 3 position switch on my transmitter, using only one channel, to control my onboard LEDs and Buzzer. After a quick look around i realized that that was not an easy thing to do (correct me if i am wrong). So i ended up writing a lua script to get it done. I am using a matek H-743 board and some 2812 matek leds (neopixel). Board uses servo_13 as an LED port and i am using 12 LEDs in line across the leading edge of each wing. The two lines of leds (one on the left and one on the right wing) are connected with a Y cable to servo_13.
If pwm on the selected channel is <1300 then both leds and buzzer are OFF.
If pwm on the selected channel is >1300 and <1600 leds are ON (red) and buzzer is OFF.
If pwm on the selected channel is >1600 buzzer is ON and LEDs are Flashing (white).
I am posting it in case someone finds it useful or has a more effective way to do it!
local channel = 6 -- rc channel controling LEDs and Buzzer. (Need to be calibrated in the radio calibration 1000-2000us)
local led_pin = 13 --LEDs servo pin (SERVO13 for MATEK-H743)
serialLED:set_num_neopixel(led_pin, 12) --"neopixel" for Matek-2812 using "12" LEDs. "profiled" might be your led type
local led_sw_on = false
local buz_sw_on = false
local led_status = false
local led_flash = false
local buz_status = false
function update()
local pwm_val = rc:get_pwm(channel)
if pwm_val < 1300 then
led_sw_on = false
buz_sw_on = false
elseif pwm_val > 1300 and pwm_val < 1600 then
led_sw_on = true
buz_sw_on = false
elseif pwm_val > 1600 then
led_sw_on = false
buz_sw_on = true
end
if led_sw_on and not led_status then
gcs:send_text(6, "Turning LEDs: ON")
serialLED:set_RGB(led_pin, -1, 255, 0, 0)
led_status = true
elseif not led_sw_on and led_status then
gcs:send_text(6, "Turning LEDs: OFF")
serialLED:set_RGB(led_pin, -1, 0, 0, 0)
led_status = false
end
serialLED:send(led_pin)
if buz_sw_on then
if not buz_status then
gcs:send_text(6, "Turning BUZZER: ON")
buz_status = true
end
notify:play_tune("MBT200>C#2A#2C#2A#2")
if not led_flash then
serialLED:set_RGB(led_pin, -1, 255, 255, 255)
led_flash = true
else
serialLED:set_RGB(led_pin, -1, 0, 0, 0)
led_flash = false
end
serialLED:send(led_pin)
else
if buz_status then
gcs:send_text(6, "Turning BUZZER: OFF")
buz_status = false
serialLED:set_RGB(led_pin, -1, 0, 0, 0)
serialLED:send(led_pin)
end
end
return update, 1000 --check every 1 seconds
end
return update, 5000 --run 5 seconds after boot