Skip to content

Commit

Permalink
Add more RGB LED lua scripts for MT12 (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
zyren authored Dec 12, 2023
1 parent 686006f commit 4ca86de
Show file tree
Hide file tree
Showing 15 changed files with 588 additions and 2 deletions.
68 changes: 68 additions & 0 deletions sdcard/bw128x64/SCRIPTS/RGBLED/Bback.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
local function init()
colorChangeTime = getTime() -- Initialize time
phase = 0
currentLed = 0 -- Current lit LED position
scroll_oldtime = getTime() -- Initialize scroll_oldtime
scroll_cycle = 0 -- Initialize scroll_cycle
end

-- Function to generate smooth cyclic colors
local function getColor(phase, length)
local position = (phase % length) / length
local r, g, b = 0, 0, 0
local maxBrightness = 255 -- Maximum brightness value

-- RGB color transition: red -> green -> blue -> red
if position < 1/3 then
-- From red to green
r = maxBrightness * (1 - 3 * position)
g = maxBrightness * (3 * position)
elseif position < 2/3 then
-- From green to blue
position = position - 1/3
g = maxBrightness * (1 - 3 * position)
b = maxBrightness * (3 * position)
else
-- From blue to red
position = position - 2/3
b = maxBrightness * (1 - 3 * position)
r = maxBrightness * (3 * position)
end

-- Skip colors that are close to the background color
local bg_r, bg_g, bg_b = 0, 0, 72 -- Background color
local threshold = 30 -- Color difference threshold
if math.abs(r - bg_r) < threshold and math.abs(g - bg_g) < threshold and math.abs(b - bg_b) < threshold then
return getColor((phase + 1) % length, length) -- Skip this color and get the next one
end

return r, g, b
end

local colorPhase = 0 -- Initialize color phase

local function run()
for i=LED_STRIP_LENGTH - 1, 0, -1 do -- Reverse iteration
if (i == scroll_cycle) then
local r, g, b = getColor(colorPhase, 255)
setRGBLedColor(i, r, g, b)
else
setRGBLedColor(i, 0, 0, 72)
end
end
if ((getTime() - scroll_oldtime) > 8) then
scroll_oldtime = getTime()
scroll_cycle = scroll_cycle - 1 -- Decrement scroll_cycle
if (scroll_cycle < 0) then
scroll_cycle = LED_STRIP_LENGTH - 1 -- Reset scroll_cycle to the end of the strip
end
end
colorPhase = (colorPhase + 1) % 255 -- Update color phase
applyRGBLedColors()
end

local function background()
-- Called periodically while the Special Function switch is off
end

return { run=run, background=background, init=init }
68 changes: 68 additions & 0 deletions sdcard/bw128x64/SCRIPTS/RGBLED/Bfwrd.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
local function init()
colorChangeTime = getTime() -- Initialize time
phase = 0
currentLed = 0 -- Current lit LED position
scroll_oldtime = getTime() -- Initialize scroll_oldtime
scroll_cycle = 0 -- Initialize scroll_cycle
end

-- Function to generate smooth cyclic colors
local function getColor(phase, length)
local position = (phase % length) / length
local r, g, b = 0, 0, 0
local maxBrightness = 255 -- Maximum brightness value

-- RGB color transition: red -> green -> blue -> red
if position < 1/3 then
-- From red to green
r = maxBrightness * (1 - 3 * position)
g = maxBrightness * (3 * position)
elseif position < 2/3 then
-- From green to blue
position = position - 1/3
g = maxBrightness * (1 - 3 * position)
b = maxBrightness * (3 * position)
else
-- From blue to red
position = position - 2/3
b = maxBrightness * (1 - 3 * position)
r = maxBrightness * (3 * position)
end

-- Skip colors that are close to the background color
local bg_r, bg_g, bg_b = 0, 0, 72 -- Background color
local threshold = 30 -- Color difference threshold
if math.abs(r - bg_r) < threshold and math.abs(g - bg_g) < threshold and math.abs(b - bg_b) < threshold then
return getColor((phase + 1) % length, length) -- Skip this color and get the next one
end

return r, g, b
end

local colorPhase = 0 -- Initialize color phase

local function run()
for i=0, LED_STRIP_LENGTH - 1, 1 do
if (i == scroll_cycle) then
local r, g, b = getColor(colorPhase, 255)
setRGBLedColor(i, r, g, b)
else
setRGBLedColor(i, 0, 0, 72)
end
end
if ((getTime() - scroll_oldtime) > 8) then
scroll_oldtime = getTime()
scroll_cycle = scroll_cycle + 1
if (scroll_cycle >= LED_STRIP_LENGTH) then
scroll_cycle = 0
end
end
colorPhase = (colorPhase + 1) % 255 -- Update color phase
applyRGBLedColors()
end

local function background()
-- Called periodically while the Special Function switch is off
end

return { run=run, background=background, init=init }
68 changes: 68 additions & 0 deletions sdcard/bw128x64/SCRIPTS/RGBLED/Pback.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
local function init()
colorChangeTime = getTime() -- Initialize time
phase = 0
currentLed = 0 -- Current lit LED position
scroll_oldtime = getTime() -- Initialize scroll_oldtime
scroll_cycle = 0 -- Initialize scroll_cycle
end

-- Function to generate smooth cyclic colors
local function getColor(phase, length)
local position = (phase % length) / length
local r, g, b = 0, 0, 0
local maxBrightness = 255 -- Maximum brightness value

-- RGB color transition: red -> green -> blue -> red
if position < 1/3 then
-- From red to green
r = maxBrightness * (1 - 3 * position)
g = maxBrightness * (3 * position)
elseif position < 2/3 then
-- From green to blue
position = position - 1/3
g = maxBrightness * (1 - 3 * position)
b = maxBrightness * (3 * position)
else
-- From blue to red
position = position - 2/3
b = maxBrightness * (1 - 3 * position)
r = maxBrightness * (3 * position)
end

-- Skip colors that are close to the background color
local bg_r, bg_g, bg_b = 72, 0, 72 -- Background color
local threshold = 30 -- Color difference threshold
if math.abs(r - bg_r) < threshold and math.abs(g - bg_g) < threshold and math.abs(b - bg_b) < threshold then
return getColor((phase + 1) % length, length) -- Skip this color and get the next one
end

return r, g, b
end

local colorPhase = 0 -- Initialize color phase

local function run()
for i=LED_STRIP_LENGTH - 1, 0, -1 do -- Reverse iteration
if (i == scroll_cycle) then
local r, g, b = getColor(colorPhase, 255)
setRGBLedColor(i, r, g, b)
else
setRGBLedColor(i, 72, 0, 72)
end
end
if ((getTime() - scroll_oldtime) > 8) then
scroll_oldtime = getTime()
scroll_cycle = scroll_cycle - 1 -- Decrement scroll_cycle
if (scroll_cycle < 0) then
scroll_cycle = LED_STRIP_LENGTH - 1 -- Reset scroll_cycle to the end of the strip
end
end
colorPhase = (colorPhase + 1) % 255 -- Update color phase
applyRGBLedColors()
end

local function background()
-- Called periodically while the Special Function switch is off
end

return { run=run, background=background, init=init }
68 changes: 68 additions & 0 deletions sdcard/bw128x64/SCRIPTS/RGBLED/Pfwrd.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
local function init()
colorChangeTime = getTime() -- Initialize time
phase = 0
currentLed = 0 -- Current lit LED position
scroll_oldtime = getTime() -- Initialize scroll_oldtime
scroll_cycle = 0 -- Initialize scroll_cycle
end

-- Function to generate smooth cyclic colors
local function getColor(phase, length)
local position = (phase % length) / length
local r, g, b = 0, 0, 0
local maxBrightness = 255 -- Maximum brightness value

-- RGB color transition: red -> green -> blue -> red
if position < 1/3 then
-- From red to green
r = maxBrightness * (1 - 3 * position)
g = maxBrightness * (3 * position)
elseif position < 2/3 then
-- From green to blue
position = position - 1/3
g = maxBrightness * (1 - 3 * position)
b = maxBrightness * (3 * position)
else
-- From blue to red
position = position - 2/3
b = maxBrightness * (1 - 3 * position)
r = maxBrightness * (3 * position)
end

-- Skip colors that are close to the background color
local bg_r, bg_g, bg_b = 72, 0, 72 -- Background color
local threshold = 30 -- Color difference threshold
if math.abs(r - bg_r) < threshold and math.abs(g - bg_g) < threshold and math.abs(b - bg_b) < threshold then
return getColor((phase + 1) % length, length) -- Skip this color and get the next one
end

return r, g, b
end

local colorPhase = 0 -- Initialize color phase

local function run()
for i=0, LED_STRIP_LENGTH - 1, 1 do
if (i == scroll_cycle) then
local r, g, b = getColor(colorPhase, 255)
setRGBLedColor(i, r, g, b)
else
setRGBLedColor(i, 72, 0, 72)
end
end
if ((getTime() - scroll_oldtime) > 8) then
scroll_oldtime = getTime()
scroll_cycle = scroll_cycle + 1
if (scroll_cycle >= LED_STRIP_LENGTH) then
scroll_cycle = 0
end
end
colorPhase = (colorPhase + 1) % 255 -- Update color phase
applyRGBLedColors()
end

local function background()
-- Called periodically while the Special Function switch is off
end

return { run=run, background=background, init=init }
2 changes: 1 addition & 1 deletion sdcard/bw128x64/SCRIPTS/RGBLED/blue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ end
local function run()
for i=0, LED_STRIP_LENGTH - 1, 1
do
setRGBLedColor(i, 0, 0, 50)
setRGBLedColor(i, 0, 0, 128)
end
applyRGBLedColors()
end
Expand Down
52 changes: 52 additions & 0 deletions sdcard/bw128x64/SCRIPTS/RGBLED/flow.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
local function init()
colorChangeTime = getTime() -- Initialize time
phase = 0
end

local minBrightness = 0 -- Minimum brightness value
local maxBrightness = 255 -- Maximum brightness value

local function getColor(phase, length)
local position = (phase % length) / length
local r, g, b = minBrightness, minBrightness, minBrightness

-- RGB color transition: red -> green -> blue -> red
if position < 1/3 then
-- From red to green
r = maxBrightness * (1 - 32 * position)
g = maxBrightness * (32 * position)
elseif position < 2/3 then
-- From green to blue
position = position - 1/3
g = maxBrightness * (1 - 32 * position)
b = maxBrightness * (32 * position)
else
-- From blue to red
position = position - 2/3
b = maxBrightness * (1 - 32 * position)
r = maxBrightness * (32 * position)
end

return r, g, b
end

local colorChangeTime = 0 -- The time of the last color change

local function run()
if ((getTime() - colorChangeTime) > 1) then -- Use an interval of 2 time units
colorChangeTime = getTime()
phase = (phase + 1) % 255 -- Update color phase

for i = 0, LED_STRIP_LENGTH - 1, 1 do
local r, g, b = getColor(phase + i * 64, 255) -- Increase phase offset for each LED
setRGBLedColor(i, r, g, b)
end
applyRGBLedColors()
end
end

local function background()
-- Called periodically while the Special Function switch is off
end

return { run=run, background=background, init=init }
2 changes: 1 addition & 1 deletion sdcard/bw128x64/SCRIPTS/RGBLED/green.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ end
local function run()
for i=0, LED_STRIP_LENGTH - 1, 1
do
setRGBLedColor(i, 0, 50, 0)
setRGBLedColor(i, 0, 255, 0)
end
applyRGBLedColors()
end
Expand Down
16 changes: 16 additions & 0 deletions sdcard/bw128x64/SCRIPTS/RGBLED/orange.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local function init()
end

local function run()
for i=0, LED_STRIP_LENGTH - 1, 1
do
setRGBLedColor(i, 255, 100, 0) -- Change RGB values to represent orange color
end
applyRGBLedColors()
end

local function background()
-- Called periodically while the Special Function switch is off
end

return { run=run, background=background, init=init }
16 changes: 16 additions & 0 deletions sdcard/bw128x64/SCRIPTS/RGBLED/purple.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local function init()
end

local function run()
for i=0, LED_STRIP_LENGTH - 1, 1
do
setRGBLedColor(i, 255, 0, 255) -- Set to purple color
end
applyRGBLedColors()
end

local function background()
-- Called periodically while the Special Function switch is off
end

return { run=run, background=background, init=init }
Loading

0 comments on commit 4ca86de

Please sign in to comment.