2.1 点灯
-
学习:【Buildroot】系统使用文档----点灯
-
硬件引脚:实际没啥用,系统里面靠驱动点灯,没有驱动无法直接操作IO口
-
led设备驱动:
root@linux:/home/lckfb# ls /sys/class/leds/ mmc0:: rgb-led-b rgb-led-g rgb-led-r
-
led相关属性:
root@linux:/home/lckfb# ls /sys/class/leds/rgb-led-r/ brightness device max_brightness power subsystem trigger uevent
-
trigger:led的工作模式
-
none
: 禁用触发器,LED 保持灭。此时可以向brightness写入数据控制led亮灭echo "none" > /sys/class/leds/rgb-led-r/trigger
-
timer
:根据设定的时间间隔触发。切换到此模式后,会多出来两个属性,delay_off:灭灯持续时间;delay_on:亮灯持续时间;root@linux:/home/lckfb# ls /sys/class/leds/rgb-led-r/ brightness delay_off delay_on device max_brightness power subsystem trigger uevent
定时模式:写入后切换到默认闪灯状态,500ms亮,500ms灭 echo "timer" > /sys/class/leds/rgb-led-r/trigger 改变亮灯持续时间:亮灯状态持续20s echo "20000" > /sys/class/leds/rgb-led-r/delay_on 改变灭灯持续时间:灭灯状态持续20s echo "20000" > /sys/class/leds/rgb-led-r/delay_off
-
其他:不同的触发模式
root@linux:/home/lckfb# cat /sys/class/leds/rgb-led-r/trigger none rfkill-any rfkill-none kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock mmc2 mmc0 [timer] rfkill0 mmc1 rfkill1 rfkill2 rfkill3
-
-
板子默认状态为RGB灯交替显示,可以通过如下指令关闭
关闭rgb-led-r: echo "none" > /sys/class/leds/rgb-led-r/trigger 关闭rgb-led-g: echo "none" > /sys/class/leds/rgb-led-g/trigger 关闭rgb-led-b: echo "none" > /sys/class/leds/rgb-led-b/trigger
-
brightness:写0为灭灯,写非0为亮灯,无法调节亮度,仅在trigger为none模式下有效,在trigger为timer模式下,写入数据无效,读取数据有效;任何时候可以通过读取此属性来判断led灯的状态
rgb-led-r灯亮:以下三条结果一样,无法调节亮度,非零即为亮灯 echo "1" > /sys/class/leds/rgb-led-r/brightness echo "100" > /sys/class/leds/rgb-led-r/brightness echo "255" > /sys/class/leds/rgb-led-r/brightness rgb-led-r灯灭: echo "0" > /sys/class/leds/rgb-led-r/brightness
-
脚本控制
- 参考:ubuntu写一个.sh脚本文件:https://blog.csdn.net/xiaomifanhxx/article/details/82285881
Bash脚本循环:https://wangdoc.com/bash/loop
linux shell脚本中的延时:https://blog.csdn.net/cbffyx/article/details/8955979 - 实际代码:
#!/bin/bash # All led off echo "none" > /sys/class/leds/rgb-led-r/trigger echo "none" > /sys/class/leds/rgb-led-g/trigger echo "none" > /sys/class/leds/rgb-led-b/trigger while true; do # led on echo "1" > /sys/class/leds/rgb-led-r/brightness echo "rgb-led-r ON" sleep 1s # led off echo "0" > /sys/class/leds/rgb-led-r/brightness echo "rgb-led-r OFF" sleep 1s done
- 参考:ubuntu写一个.sh脚本文件:https://blog.csdn.net/xiaomifanhxx/article/details/82285881