RGB温度指示器的制作

第1步:你需要什么。
《从技术上讲,大多数基础产品教程通常以“hello world!”开头。例如,甚至是一个“blink”示例,由于您在某些时候使用过arduino或raspberry pi,因此您可能已经非常熟悉它。但是我不想从头开始,因为每个人都在做同样的事情,这使得它真的有点无聊。
相反,我想从一个实际的项目想法开始。如果你愿意的话,它既简单又可扩展到更复杂的项目构想。
以下是我们需要的项目(参考instructable本节提供的照片):
ip02 - 高级usb编程接口
cc03 - arm cortex m0 + core
sw02 - voc和气象传感器(使用bosch的bme680传感器)
xbus连接器 - 启用不同xchip之间的i2c通信(x2)
xpdi连接器 - 启用编程和调试(x1)
步骤2:连接件
要将所有部分连接在一起,我们将首先从1个xbus连接器和xpdi连接器开始。
按照我提供的图像,注意xchip的方向和连接器的位置。
在ip02和&之间。 cc03 xchips,很容易识别连接点。
对于cc03,它将是南侧。对于ip02,它将是xchip的北侧。
一旦完成,我们将在cc03 xchip的西侧添加另一个xbus连接器。
完成?
现在,只需将sw02 xchip连接到cc03的西侧。
在我们将ip02插入笔记本电脑之前,请确保为这两个开关选择以下选项:
b (左侧开关)
选择 dce (右侧开关)
最后,我们现在准备将ip02插入笔记本电脑并开始设置arduino ide。
步骤3:设置arduino ide
同样,在这个教程中,我假设你已经熟悉了arduino ide环境以及如何在开发环境中管理库。
为了这个项目的目的,我们需要两个主要的库:
arduino-core
sw02库
将两个库下载到桌面上的某个位置。
接下来,启动arduino ide 。
从主菜单中选择“草图”》“包含库”》“添加.zip库。..”
重复相同的过程两个库文件。
接下来,我们需要选择相关的“board”以及“port”。 (请注意,我还使用橙色框突出显示了必要的选项。
board:“arduino/genuino zero(原生usb端口)”
端口:“comxx”(这应该是根据您机器上反映的com端口。我的是使用com31)
好吧!我知道你一直渴望进入编码,所以在下一步,这就是我们将关注的重点。
第4步:代码时间
在本节中,我将首先从已完成的项目代码中共享代码片段。最后,我将发布完整的源代码,使您可以轻松地将代码复制并粘贴到arduino ide源文件中。
标题文件:
#include /* this is the library for the main xinabox core functions. */
#include /* this is the library for the voc & weather sensor xchip. */
定义一些用于控制rgb led信号的常量:
#define redledpin a4
#define greenledpin 8
#define blueledpin 9
接下来,我们需要声明一个函数原型来传递rgb值。
void setrgbcolor(int redvalue, int greenvalue, int bluevalue);
声明sw02对象:
xsw02 sw02;
setup()方法:
void setup() {
// start the i2c communication
wire.begin();
// start the sw02 sensor
sw02.begin();
// delay for sensor to normalise
delay(5000);
}
现在主循环():
void loop() {
float tempc;
}
接下来,我们需要使用我们之前在程序中创建的sw02对象进行轮询,以开始与传感器芯片的通信:
// read and calculate data from sw02 sensor
sw02.poll();
现在,我们正在读取传感器的温度读数。
tempc = sw02.gettempc();
一旦我们读完了,我们要做的最后一件事是使用一系列if 。.. else 。..控制语句来确定温度范围,然后调用setrgbcolor()函数。
// you can adjust the temperature range according to your climate. for me, i live in singapore,
// which is tropical all year round, and the temperature range can be quite narrow here.
if (tempc 》= 20 && tempc 《 25) {
setrgbcolor(0, 0, 255);
} else if (tempc 》= 25 && tempc 《 30) {
setrgbcolor(0, 255, 0);
} else if (tempc 》= 30 && tempc 《 32) {
setrgbcolor(255, 190, 9);
} else if (tempc 》= 32 && tempc 《 35) {
setrgbcolor(243, 122, 0);
} else if (tempc 》= 35) {
setrgbcolor(255, 0, 0);
}
注意:如果您有兴趣知道特定颜色的相关rgb值是什么,我会记录推荐你做谷歌搜索“rgb颜色值”。有很多站点可以使用颜色选择器来选择你想要的颜色。
// if you like to, and it is optional, you can also add a delay in between polling for the sensor‘s readings.
delay(delay_time);
你可以在开始时声明delay_time常量对于程序,这样,您只需要修改它的值一次,而不是在整个程序中的多个位置。最后,我们需要控制rgb led的功能:
void setrgbcolor(int redvalue, int greenvalue, int bluevalue) {
analogwrite(redledpin, redvalue);
analogwrite(greenledpin, greenvalue);
analogwrite(blueledpin, bluevalue);
}
最终程序
#include
#include
#define redledpin a4
#define greenledpin 8
#define blueledpin 9
void setrgbcolor(int redvalue, int greenvalue, int bluevalue);
const int delay_time = 1000;
xsw02 sw02;
void setup() {
// start the i2c communication
wire.begin();
// start the sw02 sensor
sw02.begin();
// delay for sensor to normalise
delay(5000);
}
void loop() {
// create a variable to store the data read from sw02
float tempc;
tempc = 0;
// read and calculate data from sw02 sensor
sw02.poll();
// request sw02 to get the temperature measurement and store in the
// temperatue variable
tempc = sw02.gettempc();
if (tempc 》= 20 && tempc 《 25) {
setrgbcolor(0, 0, 255);
} else if (tempc 》= 25 && tempc 《 30) {
setrgbcolor(0, 255, 0);
} else if (tempc 》= 30 && tempc 《 32) {
setrgbcolor(255, 190, 9);
} else if (tempc 》= 32 && tempc 《 35) {
setrgbcolor(243, 122, 0);
} else if (tempc 》= 35) {
setrgbcolor(255, 0, 0);
}
// small delay between sensor reads
delay(delay_time);
}
void setrgbcolor(int redvalue, int greenvalue, int bluevalue) {
analogwrite(redledpin, redvalue);
analogwrite(greenledpin, greenvalue);
analogwrite(blueledpin, bluevalue);
}
现在我们的程序准备好了,让我们来吧编程xchip!上传过程与将程序上传到arduino板的过程完全相同。
完成后,为什么不拔掉电源插头并将其带出来进行试运行。
查看我自己在室外测试项目时创建的短暂时间视频。我还使用了pb04(双aa智能电池)xchip,当它没有连接到笔记本电脑时为项目供电,使其紧凑和移动。
我还在下一步附加了arduino项目文件。随意下载并运行它! :)

大数据的4v特征有哪些 大数据技术包括哪些技术
采用PLC和变频器结合实现变频恒压供水系统的设计
国内市场竞争激烈,单飞的荣耀面临哪些发展困难?
Teledyne e2v的Emerald图像传感器推出了新品
用Riva和NeMo Megatron构建语音AI
RGB温度指示器的制作
我国集成电路产业与全球还存在哪些差距
安全多方计算技术解析
说说那些你不知道的电路设计及PCB布线时的可靠性原则
安规电容坏了怎么测量_安规电容坏了的表现
透光型编码器的结构是什么
第三届CIOC地产智能科技峰会已在上海圆满闭幕
人工智能AI在医学上的进展
自动驾驶层级开发出哪些具备市场应用前景的技术?
常用仪表设备如何进行维护保养快速接线模块如何方便维修等资料概述
电压跟随器是什么?电压跟随器的特点和作用以及电路特点解析,如何计算?
嵌入式芯片中神经网络加速器如何支持本地化AI处理
智能浴霸语音识别控制芯片,智能声控开关芯片方案WT6900H-24SS
降低UPS电源总故障率的方法盘点
stm32f4ZG 和 cc2530f256的移植教程