使用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 ](jie.tang@dfrobot.com)
* @versionV1.0.1
* @date2022-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 ](jie.tang@dfrobot.com)
* @versionV1.0.1
* @date2022-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());
}
页:
[1]