mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-22 15:53:56 -04:00
AP_Scripting: add an applet to control LED brightness with a switch
This commit is contained in:
parent
63f28b6720
commit
63805a00a9
30
libraries/AP_Scripting/applets/leds_on_a_switch.lua
Normal file
30
libraries/AP_Scripting/applets/leds_on_a_switch.lua
Normal 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
|
6
libraries/AP_Scripting/applets/leds_on_a_switch.md
Normal file
6
libraries/AP_Scripting/applets/leds_on_a_switch.md
Normal 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
|
Loading…
Reference in New Issue
Block a user