Created
January 23, 2024 15:41
-
-
Save davidliyutong/2ca366d969eff8bbe31d7f3327340a4b to your computer and use it in GitHub Desktop.
Scirpt to change color of RGB LED on Unifi U6-Mesh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This function takes RGB values and writes them to the LED device | |
set_led_color() { | |
echo -n "$1,$2,$3" > /proc/ubnt_ledbar/custom_color | |
} | |
# This function smoothly transitions from one color to another | |
transition_color() { | |
local startR=$1 | |
local startG=$2 | |
local startB=$3 | |
local endR=$4 | |
local endG=$5 | |
local endB=$6 | |
local steps=20 # Use fewer steps since we're using a longer sleep duration | |
local i=0 | |
while [ $i -le $steps ]; do | |
local r=$(awk "BEGIN {print int($startR + ($endR - $startR) * $i / $steps)}") | |
local g=$(awk "BEGIN {print int($startG + ($endG - $startG) * $i / $steps)}") | |
local b=$(awk "BEGIN {print int($startB + ($endB - $startB) * $i / $steps)}") | |
set_led_color $r $g $b | |
sleep 1 # Use full second sleep | |
i=$((i + 1)) | |
done | |
} | |
# The main loop to cycle through colors | |
while true; do | |
# Transition from red to orange | |
transition_color 254 0 0 254 165 0 | |
# Transition from orange to yellow | |
transition_color 254 165 0 254 254 0 | |
# Transition from yellow to green | |
transition_color 254 254 0 0 254 0 | |
# Transition from green to blue | |
transition_color 0 254 0 0 0 254 | |
# Transition from blue to purple | |
transition_color 0 0 254 160 32 240 | |
# Transition from purple back to red | |
transition_color 160 32 240 254 0 0 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment