Go Down

Topic: "a function-definition is not allowed here before '{' token" error (Read 895 times) previous topic - next topic

ylling

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

刪除字符{和},並用鍵盤上鍵入的相同字符替換,然後再試一次。
我更改過後還是顯示一樣的錯誤...
不管我是用英文輸入或是中文

UKHeliBob

Translation of error message

Code: [Select]

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.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

6v6gt

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

6v6gt

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.

ylling

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




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.

Code: [Select]

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

UKHeliBob

@ylling - please stop posting pictures and post text instead as previously requested
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

ylling

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

Code: [Select]

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

Code: [Select]
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 編譯錯誤

ylling

@ ylling-請停止調整圖片並轉換文字,而不是按照先前的要求
了解,不能發布圖片只能發布文字對嗎?:o

6v6gt

OK. Replace this line:

Code: [Select]
DHT dht (dhtPin, dhtType); //Initialize DHT sensor

with this alternative:

Code: [Select]
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.

UKHeliBob

了解,不能發布圖片只能發布文字對嗎?: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
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

ylling

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

Code: [Select]
DHT dht (dhtPin, dhtType); //Initialize DHT sensor



Code: [Select]
DHT dht (dhtPin, 11 ) ; //Initialize DHT sensor (check)




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

Code: [Select]
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 編譯錯誤。



6v6gt

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.

ylling

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

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

6v6gt

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.

Go Up