【试用测评】FireBeetle ESP32-E扩展板——温感灯
【数字RGB全彩LED】
数字RGB全彩LED模块是一款可级联的RGB全彩单灯珠模块。与传统RGB全彩灯珠需要3根控制信号线,硬件占用资源多不同,该模块控制仅需一根信号线,符合Gravity-3P数字接口规范,配合DF各类扩展板,即插即用,可方便用于Arduino、micro:bit、ESP32、LattePanda、树莓派等各类主控平台。
【安装Adafruit NeoPixel库】
https://www.arduinolibraries.info/libraries/adafruit-neo-pixel
【安装灯】
【亮灯】
程序
#include <Adafruit_NeoPixel.h>
#define PIN 16
#define NUMPIXELS 1
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pixels.begin();
}
void loop() {
pixels.clear();
pixels.setPixelColor(0, pixels.Color(255,0, 0));
pixels.show();
}
【SHT31-F数字温湿度传感器】
Gravity: SHT31-F数字温湿度传感器采用业内知名的瑞士Sensirion公司推出的新一代SHT31-F温湿度传感器芯片。得益于Sensirion的CMOSens®技术,高集成度电容式测湿元件和能隙式测温元件,SHT31-F能够提供极高的可靠性和出色的长期稳定性,具有功耗低、反应快、抗干扰能力强等优点。IIC通讯,兼容3.3V/5V,可以非常容易的集成到智能楼宇、天气站、仓库存储、养殖、孵化等应用场景中。
#include <DFRobot_SHT3x.h>
//DFRobot_SHT3x sht3x(&Wire,/*address=*/0x45,/*RST=*/4);
DFRobot_SHT3x sht3x;
void setup() {
Serial.begin(9600);
//Initialize the chip
while (sht3x.begin() != 0) {
Serial.println("Failed to Initialize the chip, please confirm the wire connection");
delay(1000);
}
/**
* readSerialNumber Read the serial number of the chip.
* @return Return 32-digit serial number.
*/
Serial.print("Chip serial number");
Serial.println(sht3x.readSerialNumber());
if(!sht3x.softReset()){
Serial.println("Failed to Initialize the chip....");
}
Serial.println("------------------Read adta in single measurement mode-----------------------");
}
void loop() {
Serial.print("Ambient Temperature(°C/F):");
Serial.print(sht3x.getTemperatureC());
Serial.print(" C/");
Serial.print(sht3x.getTemperatureF());
Serial.print(" F ");
Serial.print("Relative Humidity(%RH):");
Serial.print(sht3x.getHumidityRH());
Serial.println(" %RH");
DFRobot_SHT3x::sRHAndTemp_t data = sht3x.readTemperatureAndHumidity(sht3x.eRepeatability_High);
if(data.ERR == 0){
Serial.print("Ambient Temperature(°C/F):");
Serial.print(data.TemperatureC);
Serial.print(" C/");
Serial.print(data.TemperatureF);
Serial.print(" F ");
Serial.print("Relative Humidity(%RH):");
Serial.print(data.Humidity);
Serial.println(" %RH");
}
*/
delay(1000);
}
【温控灯】
扩大温度值,让灯颜色变化更加明显。
#include <Adafruit_NeoPixel.h>
#include <DFRobot_SHT3x.h>
#define PIN 16
#define NUMPIXELS 1
DFRobot_SHT3x sht3x;
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int number=0;
void setup() {
Serial.begin(9600);
while (sht3x.begin() != 0) {
Serial.println("Failed to Initialize the chip, please confirm the wire connection");
delay(1000);
}
pixels.begin();
}
void loop() {
DFRobot_SHT3x::sRHAndTemp_t data = sht3x.readTemperatureAndHumidity(sht3x.eRepeatability_High);
if(data.ERR == 0){
int number=map(int(data.TemperatureC*100),2700,3400,0,65535);
pixels.clear();
Serial.println(int(data.TemperatureC*100));
Serial.println(number);
if(number>65535){
number=65535;
}
if(number<0){
number=0;
}
int r = number >> 16;
int g = number >> 8 & 0xFF;
int b = number & 0xFF;
pixels.setPixelColor(0, pixels.Color(r,g, b));
pixels.show();
}
delay(2000);
}
https://www.bilibili.com/video/BV1Bb4y1U7Cs?share_source=copy_web
页:
[1]