"a function-definition is not allowed here before '{' token" error

6v6gt:
感謝您提供有關錯誤消息的圖片。

好的這是全部的訊息

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.

UKHeliBob:
這進展不順利。屏幕截圖通常根本無濟於事

在文章9的屏幕截圖中,黑框的底部/右側有一個按鈕。用英語將其標記為“複製錯誤消息”。單擊該按鈕,然後在執行操作時使用代碼標籤粘貼已復制的內容到新帖子中

OK我直接複製過來了
Arduino:1.8.13(Windows 10),開發板:“ Arduino Uno”

C:\ Users \ㄚㄚ\ Desktop \ 01 \ 01.ino:在函數“ void setup()”中:
01:29:14:錯誤:此處不允許在'{'標記之前的函數定義
01:44:10:錯誤:在'{'標記之前不允許在此處進行功能定義
01:64:13:錯誤:在'{'標記之前不允許在此處進行功能定義
01:86:1:錯誤:輸入末尾預期為'}'
退出狀態1
'{'標記之前的功能定義在這裡是不允許的
該報告將包含更多信息
“在編譯期間顯示詳細輸出”
文件->首選項中啟用的選項。

6v6gt:
我想英語和中文鍵盤上的字符“ {”和“}”是不同的,即使在視覺上它們看起來是相同的。

刪除字符{和},並用鍵盤上鍵入的相同字符替換,然後再試一次。

我更改過後還是顯示一樣的錯誤...
不管我是用英文輸入或是中文

Translation of error message

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.

Switch on verbose error messages. Look under “preferences” in the Arduino IDE to see this option. Then try again.

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.

basicA.ino (58 Bytes)

basicB.ino (118 Bytes)

6v6gt:
我已經附上了一個兩個非常簡單的程序。您可以嘗試編譯這些錯誤並報告可能發現的任何錯誤嗎?
這些功能提示查看您的環境是否存在基本問題。

我已運作過了都是沒問題的!!附上照片

OK.
Use program basicA.ino and copy into it each line from from the program below (taken from post #8). After adding each line, attempt to compile it. Stop as soon as you get the original error you reported.

/*
  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;

@ylling - please stop posting pictures and post text instead as previously requested

6v6gt:
好。
使用程序basicA.ino,並從下面的程序中復制每一行(摘自#8)。添加每行之後,嘗試對其進行編譯。收到報告的原始錯誤後立即停止。

/*

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() {
  /*
  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
}



這裡發生開發板 Arduino Uno 編譯錯誤

UKHeliBob:
@ ylling-請停止調整圖片並轉換文字,而不是按照先前的要求

了解,不能發布圖片只能發布文字對嗎?:o

OK. Replace this line:

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

with this alternative:

DHT dht (dhtPin, 11 ) ; //Initialize DHT sensor (check)

to see if the error message goes away.

If it does, there may be a problem with your DHT.h library.

ylling:
了解,不能發布圖片只能發布文字對嗎?:o

You can post pictures of text if you want to but posting the actual text is better as it allows it to be copied for examination in an editor or the IDE

6v6gt:
好。替換此行:使用此替代方法:查看錯誤消息是否消失。如果是這樣,則DHT.h庫可能存在問題。

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

更換後還是顯示一樣的錯誤

C:\Users\ㄚㄚ\Downloads\basicA/basicA.ino:20: undefined reference to `setup::DHT::DHT(unsigned char, unsigned char, unsigned char)'
collect2.exe: error: ld returned 1 exit status
exit status 1
開發板 Arduino Uno 編譯錯誤。

OK.
It appears you have not used the code that was supplied in post #8.
I have attached it below. It has the name basicC.ino . Please now try with basicC.ino and report any error messages.

basicC.ino (2.43 KB)

6v6gt:
好。
看來您沒有使用#8中提供的代碼。
我將其附在下面。它的名稱為basicC.ino。現在,請嘗試使用basicC.ino並報告任何錯誤消息。

已經可以上傳,並且驗證成功了 非常感謝!!!! :smiley-lol: :D ;)

Well, getting it to compile is certainly an important step.
But I fear that is not the end of your problems here.

Anyway, good luck with it.