概述
本作品可实现自动检测水杯温度,并通过RGB灯的颜色直观反映水杯温度的高低。使用时先根据制作说明
将作品组装完整,然后接上电源(9V电池或USB供电),打开主控板开关,将水杯放置在作品中间的温度传
感器探头上方即可。当温度高时,RGB灯亮红色;温度低时,亮蓝色;温度适中时,亮绿色。DIY动手组
装,锻炼动手能力,了解智能创意电子套件的使用,激发创新思维,增加学习乐趣。
使用教程
当水杯放置在色温杯垫上,温度感应探头测量水杯温度,并通过灯颜色反应水杯温度。当水温43℃以上,全红;当水温在43~33℃之间,红绿渐变色;当水温33~18℃之间,绿蓝渐变色;当水温18℃以下,全蓝;
组装说明
电子模块清单
模块名称 |
数量
|
w1主控板 |
x1
|
温度传感器 |
x1
|
RGB-LED灯 |
x4
|
电子模块连接说明
模块 |
引脚 |
说明
|
温度传感器模块 |
W1-I2C接口 |
|
RGB—LED模块x4 |
W1-3/11接口 |
4个模块串联,注意信号方向,输出接口连接至下模块输入接口
|
Arduino程序
/**************************************************************************
Copyright (C), 2017- ,
File name: 色温杯垫
Author: Tangliufeng Version: v1.4 Date:
Description:
Others:
Function List:
1.
2.
History:
1. Date: 2017/10/10 Author: tangliufeng
Modification: 更换新RGB模块
2. ...
****************************************************************************/
#include <Wire.h>
#include <avr/wdt.h>
#include "TemperatureNTC.h"
#include "Adafruit_NeoPixel.h"
#define PIXEL_PIN 3
#define PIXEL_COUNT 4
int Temperature;
uint8_t _R, _G, _B;
int i = 1;
uint8_t TEMP;
uint8_t humidity;
uint8_t SW;
long time_out;
long time_out1;
long time_out2;
uint16_t h, color1;
float s, v;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
void setup()
{
s = 1.0;
v = 0.5;
h = 0;
Serial.begin(9600);
strip.setBrightness(50);
strip.begin();
start();
strip.clear();
strip.show();
}
void loop()
{
Temperature = readTemperatureNTC(A2);
Serial.print("Temper:");
Serial.println(Temperature);
if (Temperature >= 44) //大于44度变红色
{
color1 = 0;
}
else if (Temperature <= 33)
{
color1 = map(Temperature, 18, 33, 240, 200);; //18~33度 变蓝色
}
else
{
color1 = map(Temperature, 35, 43, 120, 0); //35~43度 变红色
}
HSV2RGB(color1, s, v, _R, _G, _B);
for (uint8_t i = 0; i < PIXEL_COUNT; i++)
{
strip.setPixelColor(i, _R, _G, _B);
}
strip.show();
}
void start()
{
char x = 3;
while (x--)
{
for (uint8_t i = 0; i < PIXEL_COUNT; i++)
{
strip.setPixelColor(i, 16, 0, 0);
}
strip.show();
delay(300);
for (uint8_t i = 0; i < PIXEL_COUNT; i++)
{
strip.setPixelColor(i, 0, 16, 0);
}
strip.show();
delay(300);
for (uint8_t i = 0; i < PIXEL_COUNT; i++)
{
strip.setPixelColor(i, 0, 0, 16);
}
strip.show();
delay(300);
}
}
void HSV2RGB(uint16_t H, float S, float V, uint8_t &R, uint8_t &G, uint8_t &B)
{
uint8_t hi;
float f, p, q, t;
hi = (uint8_t)(H / 60);
f = (float)H / 60 - hi;
p = V * (1 - S);
q = V * (1 - f * S);
t = V * (1 - (1 - f) * S);
switch (hi)
{
//0: {r,g,b} = {v,t,p}
case 0:
R = V * 255;
G = t * 255;
B = p * 255;
break;
//1: {r,g,b} = {q,v,p}
case 1:
R = q * 255;
G = V * 255;
B = p * 255;
break;
//2: {r,g,b} = {p,v,t}
case 2:
R = p * 255;
G = V * 255;
B = t * 255;
break;
//3: {r,g,b} = {p,q,v}
case 3:
R = p * 255;
G = q * 255;
B = V * 255;
break;
//4: {r,g,b} = {t,p,v}
case 4:
R = t * 255;
G = p * 255;
B = V * 255;
break;
//5: {r,g,b} = {v,p,q}
case 5:
R = V * 255;
G = p * 255;
B = q * 255;
break;
default:
break;
}
}
FAQ
版本历史记录