Also ich hab jetzt schon mal die Beleuchtung mit den verscheiden Farben, aber von Blinken bin ich noch weit entfernt...
Code
--[[
LED interface for WS2812 LEDs
--]]
--[[
for this demo we will use a single strip with 32 LEDs
--]]
local num_leds = 32
--[[
use SERVOn_FUNCTION 94 for LED. We can control up to 16 separate strips of LEDs
by putting them on different channels
--]]
local chan = SRV_Channels:find_channel(94)
if not chan then
gcs:send_text(6, "LEDs: channel not set")
return
end
-- find_channel returns 0 to 15, convert to 1 to 16
chan = chan + 1
gcs:send_text(6, "LEDs: chan=" .. tostring(chan))
-- initialisation code--
serialLED:set_num_neopixel(chan, num_leds)
-- constrain a value between limits
function constrain(v, vmin, vmax)
if v < vmin then
v = vmin
end
if v > vmax then
v = vmax
end
return v
end
--[[Table of colors on a rainbow, red first
--]]
local rainbow = {
{ 255, 0, 0 },
{ 255, 127, 0 },
{ 255, 255, 0 },
{ 0, 255, 0 },
{ 0, 0, 255 },
{ 75, 0, 130 },
{ 143, 0, 255 },
}
--[[
Function to set a LED to a color on a classic rainbow spectrum, with v=0 giving red
--]]
function set_Rainbow(chan, led, v)
serialLED:set_RGB(chan, 0, 255, 255, 255)
serialLED:set_RGB(chan, 1, 255, 255, 255)
serialLED:set_RGB(chan, 2, 255, 255, 255)
serialLED:set_RGB(chan, 3, 255, 255, 255)
serialLED:set_RGB(chan, 4, 255, 255, 255)
serialLED:set_RGB(chan, 5, 255, 255, 255)
serialLED:set_RGB(chan, 6, 255, 255, 255)
serialLED:set_RGB(chan, 7, 255, 255, 255)
serialLED:set_RGB(chan, 8, 0, 255, 0)
serialLED:set_RGB(chan, 9, 0, 255, 0)
serialLED:set_RGB(chan, 10, 0, 255, 0)
serialLED:set_RGB(chan, 11, 0, 255, 0)
serialLED:set_RGB(chan, 12, 0, 255, 0)
serialLED:set_RGB(chan, 13, 0, 255, 0)
serialLED:set_RGB(chan, 14, 0, 255, 0)
serialLED:set_RGB(chan, 15, 0, 255, 0)
serialLED:set_RGB(chan, 16, 205, 0, 0)
serialLED:set_RGB(chan, 17, 205, 0, 0)
serialLED:set_RGB(chan, 18, 205, 0, 0)
serialLED:set_RGB(chan, 19, 205, 0, 0)
serialLED:set_RGB(chan, 20, 205, 0, 0)
serialLED:set_RGB(chan, 21, 205, 0, 0)
serialLED:set_RGB(chan, 22, 205, 0, 0)
serialLED:set_RGB(chan, 23, 205, 0, 0)
serialLED:set_RGB(chan, 24, 0, 0, 205)
serialLED:set_RGB(chan, 25, 0, 0, 205)
serialLED:set_RGB(chan, 26, 0, 0, 205)
serialLED:set_RGB(chan, 27, 0, 0, 205)
serialLED:set_RGB(chan, 28, 0, 0, 205)
serialLED:set_RGB(chan, 29, 0, 0, 205)
serialLED:set_RGB(chan, 30, 0, 0, 205)
serialLED:set_RGB(chan, 31, 0, 0, 205)
end
--[[
We will set the colour of the LEDs based on roll of the aircraft
--]]
function update_LEDs()
local roll = constrain(ahrs:get_roll(), math.rad(-60), math.rad(60))
for led = 0, num_leds-1 do
local v = constrain(0.5 + 0.5 * math.sin(roll * (led - num_leds/2) / (num_leds/2)), 0, 1)
set_Rainbow(chan, led, v)
end
serialLED:send(chan)
return update_LEDs, 20 -- run at 50Hz
end
return update_LEDs, 1000
Alles anzeigen