Loading... # 0x00 有两种方式控制树莓派板载的LED # 0x01 开机后方案 > 重启会失效 控制板载灯的有以下文件: ```sh # 状态灯 /sys/class/leds/led0/brightness /sys/class/leds/led0/trigger # 电源灯 /sys/class/leds/led1/brightness /sys/class/leds/led1/trigger ``` 就可以控制状态灯和电源灯 其中`brightness`文件是亮度控制,接受范围是0~255,数字越大越亮,默认是255 `trigger`文件是控制灯的模式,可以通过`cat /sys/class/leds/led0/trigger`读取模式,我的系统是树莓派爱好者基地提供的`Debian-Pi-Aarch64`,其中模式共有: > [none] usb-gadget usb-host rc-feedback kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock timer oneshot heartbeat backlight gpio cpu cpu0 cpu1 cpu2 cpu3 default-on input panic actpwr mmc1 mmc0 rfkill-any rfkill-none rfkill0 bluetooth-power hci0-power rfkill1 默认下状态灯的模式是`cpu`,电源灯的模式是`hci0-power` 将模式设为`none`就是关闭灯 示例: ```sh # 关闭状态灯 echo none | sudo tee /sys/class/leds/led0/trigger # 调节电源灯亮度 echo 125 | sudo tee /sys/class/leds/led1/brightness ``` # 0x02 开机前方案 如果想要不重启失效,就需要通过修改`/boot/config.txt`文件来实现。 首先官方文档有说明: ``` # 状态灯 act_led_trigger Choose which activity the LED tracks. Use "heartbeat" for a nice load indicator. (default "mmc") act_led_activelow Set to "on" to invert the sense of the LED (default "off") N.B. For Pi 3B, 3B+, 3A+ and 4B, use the act-led overlay. act_led_gpio Set which GPIO to use for the activity LED (in case you want to connect it to an external device) (default "16" on a non-Plus board, "47" on a Plus or Pi 2) N.B. For Pi 3B, 3B+, 3A+ and 4B, use the act-led overlay # 电源灯 pwr_led_trigger pwr_led_activelow pwr_led_gpio As for act_led_*, but using the PWR LED. Not available on Model A/B boards. # 网络灯 eth_led0 Set mode of LED0 (usually orange) (default "1"). The legal values are: 0=link/activity 1=link1000/activity 2=link100/activity 3=link10/activity 4=link100/1000/activity 5=link10/1000/activity 6=link10/100/activity 14=off 15=on eth_led1 Set mode of LED1 (usually green) (default "6"). See eth_led0 for legal values. ``` 只需要在`/boot/config.txt`中添加相应的设置就可以实现 示例,关闭所有灯: ``` #设置状态灯为none模式 dtparam=act_led_trigger=none #设置电源灯为none模式 dtparam=pwr_led_trigger=none #设置网口灯为off dtparam=eth_led0=14 dtparam=eth_led1=14 ``` Last modification:January 12, 2022 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 0 如果觉得我的文章对你有用,请随意赞赏