AP_Scripting: add an applet to control LED brightness with a switch

This commit is contained in:
Andy Piper 2023-09-29 17:12:14 +01:00 committed by Peter Hall
parent 63f28b6720
commit 63805a00a9
2 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,30 @@
-- leds_on_a_switch.lua: control led brightness with a radio switch
--
-- constants
local AuxSwitchPos = {LOW=0, MIDDLE=1, HIGH=2}
local NTF_LED_BRIGHT = Parameter("NTF_LED_BRIGHT")
local MAV_SEVERITY = {EMERGENCY=0, ALERT=1, CRITICAL=2, ERROR=3, WARNING=4, NOTICE=5, INFO=6, DEBUG=7}
-- state
local prev_pos = -1
function update()
local sw_pos = rc:get_aux_cached(300)
if sw_pos ~= prev_pos then
if sw_pos == AuxSwitchPos.LOW then
NTF_LED_BRIGHT:set(0)
gcs:send_text(MAV_SEVERITY.INFO, "LEDs turned OFF")
elseif sw_pos == AuxSwitchPos.MIDDLE then
NTF_LED_BRIGHT:set(1)
gcs:send_text(MAV_SEVERITY.INFO, "LEDs dimmed")
else
NTF_LED_BRIGHT:set(3)
gcs:send_text(MAV_SEVERITY.INFO, "LEDs turned ON")
end
prev_pos = sw_pos
end
return update, 1000
end
return update, 5000

View File

@ -0,0 +1,6 @@
# `leds_on_a_switch.lua`: change LED brightness using an RC switch
ArduPilot controls LED brightness via the parameter `NTF_LED_BRIGHT`. This script allows you to control the value of the parameter using an RC switch.
Configure an `RCx_OPTION` as 300 for scripting and load this script.
The low position will turn off the LEDs, the high position with give maximum brightness and the middle position will dim the LEDs