前言
最近听到有小伙伴们对ruff感兴趣,我也跟着加入了大军中,本篇文章展示了ruff的开发套件,以及入手后的小demo,后续持续更新
参考文献
ruff官网
ruff思否首页
开箱
如同ruff官网展示的配件如下
上手
- 我开发时使用的是windows系统,所以下载 Ruff SDK 1.11.10 (Windows-64bit): msi 安装包
- 创建项目文件,在当前目录执行下面命令
- # 查看版本号 (首次安装好MSI如果执行下面命令不成功,可以尝试重启电脑)
- rap --version
- # 初始化 Ruff 应用
- rap init
- init后会创建项目工程,使用编辑器打开由 rap 自动生成的 src/index.js js文件进行编写代码,具体可以参照下文demo,或者官网
- 将 Ruff 开发板上的 USB 接口与 USB 电源线连接,开发板成功启动后,会搭建一个名为Ruff_[]的无线热点
- 连接这个无线热点后,执行项目部署,执行下面命令
- #项目部署
- rap deploy -s
- 红色板载 LED 点亮后表示已经运行成功
- 主板运行起来后,开始好玩的东西,就是添加不同外设(外设就是图一的配件)
- 添加外设
- #添加botton外设
- rap device add button
-
- #CK002为外设型号 外设型号包装上有写 详见上文图三
- ? model: *CK002*
-
- #添加LED外设 下文DEMO需要用到LED外设,所以我这边提前添加,流程参考上方
- rap device add led
- 添加后开始进行硬件布局,这时候记得将主板断电
- #硬件进行布局和连接撒旦
- rap layout
-
- #查看硬件布局的可视图(不懂的外设怎么装,可以看看这个)
- rap layout --visual
- 部署
- #开始部署
- rap deploy -s
- #查看日志
- rap log
七彩循环灯
- // 做了个按下botton外设,led外设 循环闪烁颜色,松开botton外设,停止led灯的小demo
- $.ready(function (error) {
- if (error) {
- console.log(error);
- return;
- }
-
- const color = {
- red: 0xff0000,
- blue: 0x0000ff,
- green: 0x00ff00,
- purple: 0xff00ff,
- cyan: 0x00ffff,
- yellow: 0xffff00,
- white: 0x000000
- };
-
- const light = function(){
- setInterval(function () {
- $('#led').setRGB(color.blue);
-
- setTimeout(function () {
- $('#led').setRGB(color.green);
- }, 100);
- setTimeout(function () {
- $('#led').setRGB(color.cyan);
- }, 200);
- setTimeout(function () {
- $('#led').setRGB(color.red);
- }, 300);
- setTimeout(function () {
- $('#led').setRGB(color.purple);
- }, 400);
- setTimeout(function () {
- $('#led').setRGB(color.yellow);
- }, 500);
- setTimeout(function () {
- $('#led').setRGB(color.white);
- }, 600)
- }, 30);
- }
- // 在 `#button` 按下时点亮 `#led-r`.
- $('#button').on('push', function () {
- console.log('Button pushed.');
- light();
- $('#led-r').turnOn();
- });
-
- // 在 `#button` 释放时熄灭 `#led-r`.
- $('#button').on('release', function () {
- console.log('Button released.');
- clearInterval(light);
- $('#led-r').turnOff();
- });
- });
最终效果图


