Go Down

Topic: void loop(){ if(bt.available()){ char databt = bt.read(); //字節 if(datab (Read 274 times) previous topic - next topic

ylling

請問我的程式裡括號的部分是錯在哪呢,一直找不到答案......



#include <DHT.h>

#include <DHT_U.h>



void setup() {

#include "DHT.h"

#define dhtPin 2      //讀取DHT11 Data

#define dhtType DHT11 //選用DHT11   



#define FAN 8

#define HOT 9



#define PERIOD1 10*60*60*1000  // this is in milliseconds

#define PERIOD2 15*60*60*1000  // this is in milliseconds

#define PERIOD3 25*60*60*1000



  // millis() returns an unsigned long so we'll use that to keep track of time

  unsigned long lastTime = 0;



  /*

    控制溫度的程式

    10分鐘維持80度

    15分鐘維持70度

    25分鐘維持60度

  */



  DHT dht(dhtPin, dhtType); // Initialize DHT sensor



  int stage = 0;



  float t;



  void setup() {

    Serial.begin(9600);//設定鮑率9600

    pinMode(FAN, OUTPUT);

    pinMode(HOT, OUTPUT);



    digitalWrite(FAN, LOW);

    digitalWrite(HOT, LOW);



    dht.begin();//啟動DHT



    lastTime = millis();



    stage = 80;

  }



  void up()

  {

    if (stage >= t - 3)

    {

      digitalWrite(FAN,HIGH);

      digitalWrite(HOT,LOW);

    }

    否則(階段<= t-3)

    {

      digitalWrite(FAN,HIGH);

      digitalWrite(HOT,LOW);

    }

    其他

    {

      digitalWrite(FAN,LOW);

      digitalWrite(HOT,LOW);

    }



  }



  無效循環()

  {

    t = dht.readTemperature(); //讀取攝氏溫度

    float f = dht.readTemperature(true); //讀取華氏溫度

    如果(isnan(h)|| isnan(t)|| isnan(f)){

      Serial.println("無法從DHT傳感器讀取!");

      返回;

    }





    unsigned long now = millis();



    if(now-lastTime> = PERIOD1)//每隔PERIOD毫秒為一次

    {

      階段= 80;

    }

    否則if(now-lastTime> = PERIOD2)//每隔PERIOD毫秒為一次

    {

      階段= 70;

    }

    else if(now-lastTime> = PERIOD3)//每隔PERIOD毫秒為一次

    {

      階段= 60;

    }



  }

}



Go Up