My guess is that you have not got matched pairs of curly braces but I will not look at the code while it is in that state and much of it is not in English
In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless
void loop()
{
t = dht.readTemperature();//讀取攝氏溫度
float f = dht.readTemperature(true);//讀取華氏溫度
if (isnan(h) || isnan(t) || isnan(f))
{
Serial.println("無法從DHT傳感器讀取!");
return;
}
unsigned long now = millis();
if (now - lastTime >= PERIOD1) // this will be true every PERIOD milliseconds
{
stage = 80;
}
else if (now - lastTime >= PERIOD2) // this will be true every PERIOD milliseconds
{
stage = 70;
}
else if (now - lastTime >= PERIOD3) // this will be true every PERIOD milliseconds
{
stage = 60;
}
#define dhtPin 2 //Read DHT11 data #define dhtType DHT11 // //Insert DHT11
const byte FAN = 8;
const byte HOT = 9;
const unsigned long PERIOD1 = (10ul * 60ul * 60ul * 1000ul); //in a few units
const unsigned long PERIOD2 = (15ul * 60ul * 60ul * 1000ul); //in millimeters
const unsigned long PERIOD3 = (25ul * 60ul * 60ul * 1000ul);
// millis() returns unsigned long, so we will use it to track
unsigned long lastTime = 0;
/*
Temperature control program
Maintain 80 degrees for 10 minutes
Maintain 70 degrees for 15 minutes
Maintain 60 degrees in 25 minutes
*/
void up()
{
if (Stage >= t - 3)
{
digitalWrite(FAN, HIGH);
digitalWrite(HOT, LOW);
}
else if (Stage <= t - 3)
{
digitalWrite(FAN, HIGH);
digitalWrite(HOT, LOW);
}
else // Stage == t-3
{
digitalWrite(FAN, LOW);
digitalWrite(HOT, LOW);
}
}
void loop()
{
// t = dht.readTemperature();//Read the temperature in Celsius
float f; // = dht.readTemperature(true);//Whether read the temperature in Fahrenheit
float h;
if (isnan(h) || isnan(t) || isnan(f))
{
Serial.println("Unable to read from DHT sensor!");
return;
}
unsigned long now = millis();
if (now - lastTime >= PERIOD1) //every PERIOD count
{
Stage = 80;
}
else if (now - lastTime >= PERIOD2) //every PERIOD count is once
{
Stage = 70;
}
else if (now - lastTime >= PERIOD3) //every PERIOD count
{
Stage = 60;
}
}
/*
Temperature control program
Maintain 80 degrees for 10 minutes
Maintain 70 degrees for 15 minutes
Maintain 60 degrees in 25 minutes
*/
#include <DHT.h>
const byte dhtPin = 2; //Read DHT11 data
#define dhtType DHT11 // Insert DHT11
const byte FAN_PIN = 8;
const byte HEATER_PIN = 9;
const unsigned long PERIOD1 = (10ul * 60ul * 60ul * 1000ul); //in a few units
const unsigned long PERIOD2 = (15ul * 60ul * 60ul * 1000ul); //in millimeters
const unsigned long PERIOD3 = (25ul * 60ul * 60ul * 1000ul);
// millis() returns unsigned long, so we will use it to track
unsigned long StartTime = 0;
DHT dht (dhtPin, dhtType); //Initialize DHT sensor
int Setpoint = 0; // Desired temperature
float t, h;
void setup()
{
Serial.begin(9600);//Set the baud rate to 9600
pinMode (FAN_PIN, OUTPUT);
pinMode (HEATER_PIN, OUTPUT);
digitalWrite(FAN_PIN, LOW);
digitalWrite(HEATER_PIN, LOW);
dht.begin(); //Start DHT
StartTime = millis();
Setpoint = 0;
}
void up()
{
if (Setpoint == 0)
{
// Temperature control has ended
digitalWrite(FAN_PIN, LOW);
digitalWrite(HEATER_PIN, LOW);
return;
}
if (Setpoint >= t + 3) // Above maximum temperature
{
digitalWrite(FAN_PIN, HIGH); // Turn on the fan
digitalWrite(HEATER_PIN, LOW); // Turn off the heater
}
else if (Setpoint <= t - 3) // Below minimum temperature
{
digitalWrite(FAN_PIN, LOW); // Turn off the fan
digitalWrite(HEATER_PIN, HIGH); // Turn on the heater
}
else // Setpoint == t +/- 3
{
// In Range. Tuern off both
digitalWrite(FAN_PIN, LOW);
digitalWrite(HEATER_PIN, LOW);
}
}
void loop()
{
t = dht.readTemperature();//Read the temperature in Celsius
float f = dht.readTemperature(true);//Whether read the temperature in Fahrenheit
if (isnan(h) || isnan(t) || isnan(f))
{
Serial.println("Unable to read from DHT sensor!");
return;
}
unsigned long now = millis();
if (now - StartTime <= PERIOD1) //every PERIOD count
{
// First period.
Setpoint = 80;
}
else if (now - StartTime <= PERIOD1 + PERIOD2) //every PERIOD count is once
{
// Second period
Setpoint = 70;
}
else if (now - StartTime >= PERIOD1 + PERIOD2 + PERIOD3) //every PERIOD count
{
// Third period
Setpoint = 60;
}
else
Setpoint = 0; // All done.
up(); // Adjust temperature
}
Thank you for your picture of the error message.
In the black colored area below the the orange colored bar, we see only the last error message but if you scroll within the black area, there are certainly many more errors. We need to see all those errors.
Please use the copy and paste function of your PC to write the error message text so we can see them.
A guess is that a certain keyboard character has been used which has been rejected on your PC and has caused the errors.
This is not going well. Screen shots are usually no help at all
On the screen shot in post #9 there is a button bottom/right of the black box. In English this is labelled "Copy error messages". Click on that then paste what has been copied in a new post, using code tags when you do
I am guessing that the characters like “{“ and “}” are different on an English and a Chinese keyboard, even though visually they appear to be the same.
Delete the characters { and } and replace these with the same characters typed from your keyboard, then try again.
C:\Users\Desktop\01\01.ino: In the function "void setup()":
01:29:14: Error: function definition before the'{' tag is not allowed here
01:44:10: Error: function definition is not allowed here before the'{' mark
01:64:13: Error: function definition is not allowed here before the'{' mark
01: 86:1: Error: the end of the input is expected to be'}'
Exit status 1
The function definition before the'{' tag is not allowed here
The report will contain more information
"Show verbose output during compilation"
Options enabled in File -> Preferences.
I have attached 2 very simply programs. Can you try to compile these and report any errors that you may find.
These are designed to see if there is a basic problem with your environment.