为什么图表一直处于零,帮帮忙改一下吗-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2146|回复: 2

[已解答] 为什么图表一直处于零,帮帮忙改一下吗

[复制链接]
发表于 2019-12-3 12:36 | 显示全部楼层 |阅读模式
#define DHT11_Pin 0  //D3
#define RS 16        //D6
#define EN 5         //D5
#define LCD_D4 4     //D4
#define LCD_D5 14    //D7
#define LCD_D6 12    //D8
#define LCD_D7 13    //D9
#define Motor_Pin 15 //D10
#define BLINKER_WIFI
#define DHTTYPE DHT11

#include <Blinker.h>
#include <EduIntro.h>
#include <LiquidCrystal.h>

int Temp = 0;
int Humi = 0;
unsigned long times = 0;
float humi = 0, temp = 0;

char auth[] = "";   //设备安全密钥
char ssid[] = "";
char pswd[] = "";

DHT11 dht11(DHT11_Pin);
LiquidCrystal lcd(RS, EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
BlinkerButton Button1("motor");
BlinkerNumber Number1("temp");
BlinkerNumber Number2("humi");

void button1_callback(const String &state)
{
  Number1.print(Temp);
  Number2.print(Humi);
  BLINKER_LOG("get button state: ", state);
  if (state == BLINKER_CMD_ON)
  {
    BLINKER_LOG("Toggle on!");
    Button1.color("#FF0000");
    Button1.print("on");
    digitalWrite(Motor_Pin, HIGH);
  }
  else if (state == BLINKER_CMD_OFF)
  {
    BLINKER_LOG("Toggle off!");
    Button1.color("#000000");
    Button1.print("off");
    digitalWrite(Motor_Pin, LOW);
  }
}



void heartbeat()
{
  Number1.print(Temp);
  Number2.print(Humi);
}
void dataStorage()
{
    Blinker.dataStorage("temp", temp);
    Blinker.dataStorage("humi", humi);
}

void setup()
{
  Serial.begin(115200);
  BLINKER_DEBUG.stream(Serial);
  pinMode(Motor_Pin, OUTPUT);
  digitalWrite(Motor_Pin, LOW);
  lcd.begin(16,2);
  Button1.print("off");
  Button1.color("#000000");
  Blinker.begin(auth, ssid, pswd);
  Button1.attach(button1_callback);
  Blinker.attachHeartbeat(heartbeat);
  Blinker.attachDataStorage(dataStorage);

}

void loop()
{
  Blinker.run();
  if (millis() - times >= 2000)
  {
    dht11.update();
    Temp = dht11.readCelsius();
    Humi = dht11.readHumidity();
    Serial.print("H: ");
    Serial.print(Humi);
    Serial.print("\tC: ");
    Serial.println(Temp);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Temp:");
    lcd.print(Temp);
    lcd.setCursor(0,1);
    lcd.print("Huim:");
    lcd.print(Humi);
    if(Temp>26)
    {
      digitalWrite(Motor_Pin,HIGH);
    }
    else
    {
      digitalWrite(Motor_Pin,LOW);
    }
  }
}



QQ图片20191203123432.png

发表于 2019-12-3 13:14 | 显示全部楼层
int Temp = 0;
int Humi = 0;
unsigned long times = 0;
float humi = 0, temp = 0;

你上传的是小写的变量,确实就是0,所以显示也是0
 楼主| 发表于 2019-12-3 14:23 | 显示全部楼层
本帖最后由 sbt147 于 2019-12-3 15:43 编辑
coloz 发表于 2019-12-3 13:14
int Temp = 0;
int Humi = 0;
unsigned long times = 0;

好了,改成功了
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 18:46 , Processed in 0.260196 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表