86浏览
查看: 86|回复: 0

[进阶] 使用Arduino制造RGB_Matrix变色温度计

[复制链接]
首先,下载对应库
Arduino-librayrs-DFRobot_RGBMatrix.h
Arduino-librarys-DHT.h注意:RGB Matrix要5V3A+电流
代码:
/*!
* @file testRGBMatrix.ino
* @brief Run the routine to test the RGB LED Matrix Panel
* @copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license     The MIT License (MIT)
* @author [TangJie]](jie.tang@dfrobot.com)
* @version  V1.0.1
* @date  2022-03-23
* @url https://github.com/DFRobot/DFRobot_RGBMatrix
*/

/*!
* @file testRGBMatrix.ino
* @brief Run the routine to test the RGB LED Matrix Panel
* @copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license     The MIT License (MIT)
* @author [TangJie]](jie.tang@dfrobot.com)
* @version  V1.0.1
* @date  2022-03-23
* @url https://github.com/DFRobot/DFRobot_RGBMatrix
*/

#include <DFRobot_RGBMatrix.h>
#include<DHT.h>
#define data 4
#define code 11

#define OE    9
#define LAT   10
#define CLK   11
#define A     A0
#define B     A1
#define C     A2
#define D     A3
#define E     A4
#define WIDTH 64
#define _HIGH 128

DFRobot_RGBMatrix matrix(A, B, C, D, E, CLK, LAT, OE, false, WIDTH, _HIGH);
DHT dht2(data,code);
void temp(float item, float trem) {  // Use parentheses () instead of colon :
  if (item < 16) {
    matrix.setTextColor(matrix.Color333(0, 0, 255));
    matrix.setCursor(12, 20);
    matrix.print(item);
  }
  else if (item < 30) {
    matrix.setTextColor(matrix.Color333(0, 255, 0));
    matrix.setCursor(12, 20);
    matrix.print(item);
  }
  else {
    matrix.setTextColor(matrix.Color333(255, 0, 0));
    matrix.setCursor(12, 20);
    matrix.print(item);
  }

  if (trem < 16) {
    matrix.setTextColor(matrix.Color333(0, 0, 255));
    matrix.setCursor(12, 40);
    matrix.print(item);  // Note: You're printing 'item' here, should it be 'trem'?
  }
  else if (trem < 30) {
    matrix.setTextColor(matrix.Color333(0, 255, 0));
    matrix.setCursor(12, 40);
    matrix.print(item);  // Note: You're printing 'item' here, should it be 'trem'?
  }
  else {
    matrix.setTextColor(matrix.Color333(255, 0, 0));
    matrix.setCursor(12, 40);
    matrix.print(trem);
  }
  matrix.setCursor(12, 50);
  matrix.print('C');
  matrix.setCursor(12, 30);
  matrix.print('%');
  delay(1000);
  matrix.fillScreen(0);
}
void setup() {

  matrix.begin();
  dht2.begin();

}

void loop() {
  temp(dht2.readTemperature(),dht2.readHumidity());

}






您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
关于楼主
上海智位机器人股份有限公司 沪ICP备09038501号-4 备案 沪公网安备31011502402448

© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail