Advertisement
uriid1

OpenWRT LED Animation | Lua

Oct 7th, 2022 (edited)
767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.37 KB | None | 0 0
  1. --[[
  2.     ####--------------------------------####
  3.     #--# Author:   by uriid1            #--#
  4.     #--# License:  GNU GPLv3            #--#
  5.     #--# Telegram: @main_moderator      #--#
  6.     #--# E-mail:   appdurov@gmail.com   #--#
  7.     ####--------------------------------####
  8. --]]
  9.  
  10. local path = '/sys/class/leds/'
  11. local led = {
  12.     path..'green:power/brightness'; -- 1
  13.     path..'green:wlan/brightness';  -- 2
  14.     path..'green:lan4/brightness';  -- 3
  15.     path..'green:lan3/brightness';  -- 4
  16.     path..'green:lan2/brightness';  -- 5
  17.     path..'green:lan1/brightness';  -- 6
  18.     path..'green:wan/brightness';   -- 7
  19.     path..'green:usb/brightness';   -- 8
  20.     path..'green:qss/brightness';   -- 9
  21. }
  22.  
  23. local function set_bright(led, val)
  24.     local fd = io.open(led, 'w')
  25.     fd:write(val)
  26.     fd:close()
  27. end
  28.  
  29. function sleep(a)
  30.     local sec = os.clock() + a
  31.     while os.clock() < sec do end
  32. end
  33.  
  34. local function off_all_leds()
  35.     for i = 1, #led do
  36.         set_bright(led[i], 0)
  37.     end
  38. end
  39.  
  40. local function linear_activate_left(spd)
  41.     for i = 1, #led do
  42.         set_bright(led[i], 255)
  43.         sleep(spd)
  44.     end
  45. end
  46.  
  47. local function linear_deactivate_left(spd)
  48.     for i = #led, 1, -1 do
  49.         set_bright(led[i], 0)
  50.         sleep(spd)
  51.     end
  52. end
  53.  
  54. -- Main anim loop
  55. while true do                                                                                
  56.     off_all_leds()
  57.     linear_activate_left(0.1)
  58.     linear_deactivate_left(0.1)
  59. end
Tags: lua OpenWRT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement