打印
[技术讨论]

全志R329开发板点灯教程

[复制链接]
226|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
神棍地海棠|  楼主 | 2024-2-19 10:25 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
[color=rgba(0, 0, 0, 0.87)]等成功用串口或者ADB连接开发板之后,就可以通过终端命令对开发板进行控制了。
[color=rgba(0, 0, 0, 0.87)]接下来会介绍Tina Linux系统封装几个模块,您可以通过命令启动这几个模块的demo,操控终端几个模块的软硬件。首先是我们大学单片机课程中的必修课:点灯
[color=rgba(0, 0, 0, 0.87)]R329支持LEDC,LEDC全称 “Light Emitting Diode Controller”,是借助Linux LED标准子系统实现的LED控制模块,可以对LED灯进行点亮、亮度调节、闪烁、阵列控制等操作。LEDC模块在无屏幕智能音箱上用得很多,比如在等待配对、唤醒、音乐播放等场景,LED灯会以不同的效果表示当前状态。
[color=rgba(0, 0, 0, 0.87)]内置固件已经编译好了LEDC模块,可以直接对LED节点进行控制从而点亮LED灯。
进入LED灯路径
[color=rgba(0, 0, 0, 0.87)]首先,我们可以进入LED节点的位置查看一个LED灯三个颜色的节点(R G B):
code" style="box-sizing: inherit; -webkit-tap-highlight-color: transparent; font-size: inherit; font-family: inherit; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-width: 0px; border-style: initial; border-color: initial; position: absolute; top: 0.5em; right: 0.5em; z-index: 1; width: 1.5em; height: 1.5em; border-radius: 0.1rem; outline: none; outline-offset: 0.1rem; cursor: pointer; transition: color 0.25s ease 0s;">root@TinaLinux:/# cd /sys/class/leds/root@TinaLinux:/sys/class/leds# lssunxi_led0b  sunxi_led0g  sunxi_led0r
[color=rgba(0, 0, 0, 0.87)][color=var(--md-typeset-a-color)]
查看LED灯的配置
[color=rgba(0, 0, 0, 0.87)]三个节点分别代三个颜色,我们可以进入一个颜色节点,比如红色(R):
code" style="box-sizing: inherit; -webkit-tap-highlight-color: transparent; font-size: inherit; font-family: inherit; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-width: 0px; border-style: initial; border-color: initial; position: absolute; top: 0.5em; right: 0.5em; z-index: 1; width: 1.5em; height: 1.5em; border-radius: 0.1rem; outline: none; outline-offset: 0.1rem; cursor: pointer; transition: color 0.25s ease 0s;">root@TinaLinux:/sys/class/leds# cd sunxi_led0r/root@TinaLinux:/sys/devices/platform/soc/ledc/leds/sunxi_led0r# lsbrightness      device          subsystemdelay_off       max_brightness  triggerdelay_on        power           uevent
[color=rgba(0, 0, 0, 0.87)][color=var(--md-typeset-a-color)]
[color=rgba(0, 0, 0, 0.87)]可以看到LEDC已经做好了很多LEDC的基本操作,包括亮度调节、闪烁、延时等。
点亮一个灯
[color=rgba(0, 0, 0, 0.87)]如果我们要点亮其中一个颜色,可以把亮度值写到 brightness 里,亮度值最高为255:
code" style="box-sizing: inherit; -webkit-tap-highlight-color: transparent; font-size: inherit; font-family: inherit; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-width: 0px; border-style: initial; border-color: initial; position: absolute; top: 0.5em; right: 0.5em; z-index: 1; width: 1.5em; height: 1.5em; border-radius: 0.1rem; outline: none; outline-offset: 0.1rem; cursor: pointer; transition: color 0.25s ease 0s;">root@TinaLinux:/sys/devices/platform/soc/ledc/leds/sunxi_led0r# echo 255 > brightness
[color=rgba(0, 0, 0, 0.87)]此时LED灯会被点亮
[color=rgba(0, 0, 0, 0.87)][color=var(--md-typeset-a-color)]
调节亮度
[color=rgba(0, 0, 0, 0.87)]如果要调节亮度值的话,只需调节写到 brightness 的值即可,亮度值范围为0~255,0代表熄灭,255代表最亮:
code" style="box-sizing: inherit; -webkit-tap-highlight-color: transparent; font-size: inherit; font-family: inherit; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-width: 0px; border-style: initial; border-color: initial; position: absolute; top: 0.5em; right: 0.5em; z-index: 1; width: 1.5em; height: 1.5em; border-radius: 0.1rem; outline: none; outline-offset: 0.1rem; cursor: pointer; transition: color 0.25s ease 0s;">root@TinaLinux:/sys/devices/platform/soc/ledc/leds/sunxi_led0r# echo 255 > brightnessroot@TinaLinux:/sys/devices/platform/soc/ledc/leds/sunxi_led0r# echo 100 > brightnessroot@TinaLinux:/sys/devices/platform/soc/ledc/leds/sunxi_led0r# echo 10 > brightnessroot@TinaLinux:/sys/devices/platform/soc/ledc/leds/sunxi_led0r# echo 0 > brightness
[color=rgba(0, 0, 0, 0.87)][color=var(--md-typeset-a-color)]
[color=rgba(0, 0, 0, 0.87)][color=var(--md-typeset-a-color)]
点亮其它颜色的灯
[color=rgba(0, 0, 0, 0.87)]如果要点亮其它颜色的灯 ,只需要参照红灯,将亮度值写到绿灯和蓝灯的 brightness 里即可:
code" style="box-sizing: inherit; -webkit-tap-highlight-color: transparent; font-size: inherit; font-family: inherit; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-width: 0px; border-style: initial; border-color: initial; position: absolute; top: 0.5em; right: 0.5em; z-index: 1; width: 1.5em; height: 1.5em; border-radius: 0.1rem; outline: none; outline-offset: 0.1rem; cursor: pointer; transition: color 0.25s ease 0s;">root@TinaLinux:/sys/class/leds# echo 255 > sunxi_led0g/brightnessroot@TinaLinux:/sys/class/leds# echo 0 > sunxi_led0g/brightnessroot@TinaLinux:/sys/class/leds# echo 255 > sunxi_led0b/brightnessroot@TinaLinux:/sys/class/leds# echo 0 > sunxi_led0b/brightness
[color=rgba(0, 0, 0, 0.87)][color=var(--md-typeset-a-color)]
[color=rgba(0, 0, 0, 0.87)][color=var(--md-typeset-a-color)]
闪烁
[color=rgba(0, 0, 0, 0.87)]如果要实现LED灯闪烁的效果,把 timer 写到 trigger 即可:
code" style="box-sizing: inherit; -webkit-tap-highlight-color: transparent; font-size: inherit; font-family: inherit; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-width: 0px; border-style: initial; border-color: initial; position: absolute; top: 0.5em; right: 0.5em; z-index: 1; width: 1.5em; height: 1.5em; border-radius: 0.1rem; outline: none; outline-offset: 0.1rem; cursor: pointer; transition: color 0.25s ease 0s;">root@TinaLinux:/sys/class/leds# echo timer > sunxi_led0r/trigger
[color=rgba(0, 0, 0, 0.87)]如果你看到灯亮了,那么恭喜你,它将照亮你嵌入式开发学习的路。
[color=rgba(0, 0, 0, 0.87)]LED灯阵列操作、模块配置、源码结构、内外部接口等进阶操作请见开发文档《Tina Linux LED开发指南》:[color=var(--md-typeset-a-color)]《Tina Linux LED开发指南》下载
[color=rgba(0, 0, 0, 0.87)]同时,还可以使用三个PWM接口对LED的三色灯进行控制,但需要占用较多的引脚和资源。


使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

192

主题

200

帖子

0

粉丝