gpt4 book ai didi

c - Arduino (C) - "expected primary-expression before ' )'

转载 作者:太空宇宙 更新时间:2023-11-04 06:25:41 25 4
gpt4 key购买 nike

我有一个函数可以在我的测试文档中运行,但是当转移到我完成的项目时,我在 ';' 之前收到错误“expected ´)' token ”。

我首先包含了处于功能测试状态的程序,以及非功能代码的代码,我知道第二个仍然是困惑的,但到目前为止一直在运行,我希望能弄清楚找出为什么 while 函数会导致错误。我也很抱歉代码不是全英文而是丹麦语,我希望这不会让它完全不可能。

来自编译器的错误信息:

Skarmmedudtest_V_1_1.ino:在函数“float tagTemp_NTC()”中:Skarmmedudtest_V_1_1:142: 错误:预期:')' 在 ';' 之前 token Skarmmedudtest_V_1_1:142:错误:预期:')' 标记之前的主要表达式Skarmmedudtest_V_1_1:142:错误:预期:';'在 ')' 标记之前Skarmmedudtest_V_1_1:806:错误:预期:'}' 在输入结束

功能代码:

    #define STR 100
float ar[STR];
float x;
int i;
int sum;
float mindstLuft;
float temp;

//DENNNE VIRKER OG MÅLER MED EN NØJAGTIGHED PÅ 0.5 GRADER
void TagTemp(){
float hej = analogRead(A0);
temp = (float)0.10988796957380947*(float)hej-(float)31.34142857142854334;
}


float tagTemp_NTC()
{
int i=0;
mindstLuft=1000; //sikre at den første måling -altid- er anderledes//

while (i<STR)
{
float hej = analogRead(A0);
temp = (float)0.10988796957380947*(float)hej-(float)31.34142857142854334;
delay(1);
if(temp<mindstLuft)
{mindstLuft=temp;}
return mindstLuft;
i++;
}
}

void setup()
{
Serial.begin(9600);
}


void loop()
{
tagTemp_NTC();
Serial.print("Smallest measurement is;");
Serial.println(mindstLuft);



//}
delay(1000);
}

功能代码;

 #include <Tone.h>
#include <i2cmaster.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include <Time.h>
#include <Thermistor.h>
#include "pitches.h"
Thermistor temp(0);

// Software SPI (slower updates, more flexible pin options):
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);

// Hardware SPI (faster, but must use certain hardware pins):
// SCK is LCD serial clock (SCLK) - this is pin 13 on Arduino Uno
// MOSI is LCD DIN - this is pin 11 on an Arduino Uno
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
// Adafruit_PCD8544 display = Adafruit_PCD8544(5, 4, 3);
// Note with hardware SPI MISO and SS pins aren't used but will still be read
// and written to during SPI transfer. Be careful sharing these pins!

//////////////////GLOBALE DATAVÆRDIER/////////////////////
#define STR 100;
#define reed 52//pin connected to read switch
unsigned long start, finished, elapsed, midt;
int reedVal = 0;
int counter = 1;
int array[1];
int countLyd = 0;
float tid;
float distance;
int buttonState=1;
int count =0;
float mindstLuft;
//////////////////GLOBALE DATAVÆRDIER/////////////////////









///////////////////////////////////// UR ///////////////////////////////////////

void ur()
{

display.setTextSize(1);
display.setCursor(42,0);
display.print(hour());
taltilur(minute());
taltilur(second());
display.println();
}

void taltilur(int digits)
{
display.print(":");
if(digits < 10)
display.print('0');
display.print(digits);
}

int sensorValueNTC = analogRead(A0);
int sensorValueIFR = analogRead(A1);
int sensorValueFart = analogRead(A2);
int sensorValueDistance = analogRead(A3);

////////////////////////////////////////////////////////////////////////////////////////


int temperatureIR;

void vejTemp()
{
//////////////////////////////////KODE TIL IR SENSOR///////////////////////////////////
int dev = 0x5A<<1;
int data_low = 0;
int data_high = 0;
int pec = 0;

i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x07);

// read
i2c_rep_start(dev+I2C_READ);
data_low = i2c_readAck(); //Read 1 byte and then send ack
data_high = i2c_readAck(); //Read 1 byte and then send ack
pec = i2c_readNak();
i2c_stop();

//This converts high and low bytes together and processes temperature, MSB is a error bit and is ignored for temps
double tempFactor = 0.02; // 0.02 degrees per LSB (measurement resolution of the MLX90614)
double tempData = 0x0000; // zero out the data
int frac; // data past the decimal point

// This masks off the error bit of the high byte, then moves it left 8 bits and adds the low byte.
tempData = (double)(((data_high & 0x007F) << 8) + data_low);
tempData = (tempData * tempFactor)-0.01;

float celcius = tempData - 273.15;
float fahrenheit = (celcius*1.8) + 32;

display.setTextSize(1.5);
display.setTextColor(BLACK);
display.setCursor(0,25);
display.print("Vej temp:");
display.setTextSize(1.5);
display.setTextColor(BLACK);
display.setCursor(60,25);
display.print(celcius,1); // - temp fra infrarød
//display.print("10*");
}

////////////////////////////////////////////////////////////////////////////////////////











/////////////////////////////// NTC TEMP ///////////////////////////////////////////////
float tagTemp_NTC()
{
int i=0;
mindstLuft=1000; //sikre at den første måling -altid- er anderledes//

while (i<STR)
{
float hej = analogRead(A0);
temp = (float)0.10988796957380947*(float)hej-(float)31.34142857142854334;
delay(1);
if(temp<mindstLuft)
{mindstLuft=temp;}
return mindstLuft;
i++;
}
}

void luftTemp()
{

display.setTextSize(1.5);
display.setTextColor(BLACK);
display.setCursor(0,35);
display.print("Luft temp:");
display.setTextSize(1.5);
display.setTextColor(BLACK);
display.setCursor(60,35);
display.print(mindst_luft, 1);

//display.print("10*");
}
////////////////////////////////////////////////////////////////////////////////////////











////////////////////////////////////// DISTANCE //////////////////////////////////////////////////
void distance2()
{


float radius = 0.35; //meter. Dette skal brugeren selv skrive ind fra skaermen.
float hjulomkreds = 3.14 * (radius*2);


reedVal = digitalRead(reed);//get val of A0



if(reedVal == 1 && counter == 1)
{
counter = 0;

start = millis();

}
if(reedVal == 0 && counter == 0)
{

counter = 2;
}


if(reedVal == 1 && counter == 2)
{
finished = millis();
elapsed = (finished - start);
array[1] = elapsed;
tid = array[1];


counter = 0;
start = millis();
distance = distance + hjulomkreds;
}
delay(200);


float hastighed = ((hjulomkreds/tid)*3600);


display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(1,0);
display.print(distance); // - distance fra sensor
//display.print("10km");
}
////////////////////////////////////////////////////////////////////////////////////////









//////////////////////////////////// FART ////////////////////////////////////////////////////
void fart()
{

float radius = 0.35; //meter. Dette skal brugeren selv skrive ind fra skaermen.
float hjulomkreds = 2 * 3.14 * radius*radius;


reedVal = digitalRead(reed);//get val of A0



if(reedVal == 1 && counter == 1)
{
counter = 0;

start = millis();

}
if(reedVal == 0 && counter == 0)
{

counter = 2;
}


if(reedVal == 1 && counter == 2)
{
finished = millis();
elapsed = (finished - start);
array[1] = elapsed;
tid = array[1];


counter = 0;
start = millis();
distance = distance + 0.35;
}
delay(200);

//float hastighed = ((hjulomkreds * 3600)/tid); // Km/t
float hastighed = ((hjulomkreds/tid)*3600);


display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,10);
display.print("Fart:");
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(30,10);
display.print(hastighed, 1);
display.setCursor(60,10);
display.print("km/t");

}
////////////////////////////////////////////////////////////////////////////////////////











///////////////////////////////////// LYS DIODER ///////////////////////////////////////////////////
void lysG()
{
digitalWrite(22, HIGH);
digitalWrite(24, LOW);
digitalWrite(26, LOW);
}

void lysR()
{
digitalWrite(22, LOW);
digitalWrite(26, HIGH);
digitalWrite(24, LOW);
}

void lysY()
{
digitalWrite(22, LOW);
digitalWrite(26, LOW);
digitalWrite(24, HIGH);
}

void slukLysGreen()
{
digitalWrite(22, LOW);
}

void slukLysYellow()
{
digitalWrite(24, LOW);
}

void slukLysRed()
{
digitalWrite(26, LOW);
}
////////////////////////////////////////////////////////////////////////////////////////












///////////FUNKTIONER TIL 1 PER SKÆRM//////////////
void ur1()
{
display.clearDisplay();
display.setTextSize(2);
display.setCursor(0,20);
display.print(hour());
taltilur(minute());
taltilur(second());
display.println();
display.display();
}


void vejTemp1()
{
display.clearDisplay();
//////////////////////////////////KODE TIL IR SENSOR///////////////////////////////////
int dev = 0x5A<<1;
int data_low = 0;
int data_high = 0;
int pec = 0;

i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x07);

// read
i2c_rep_start(dev+I2C_READ);
data_low = i2c_readAck(); //Read 1 byte and then send ack
data_high = i2c_readAck(); //Read 1 byte and then send ack
pec = i2c_readNak();
i2c_stop();

//This converts high and low bytes together and processes temperature, MSB is a error bit and is ignored for temps
double tempFactor = 0.02; // 0.02 degrees per LSB (measurement resolution of the MLX90614)
double tempData = 0x0000; // zero out the data
int frac; // data past the decimal point

// This masks off the error bit of the high byte, then moves it left 8 bits and adds the low byte.
tempData = (double)(((data_high & 0x007F) << 8) + data_low);
tempData = (tempData * tempFactor)-0.01;

float celcius = tempData - 273.15;
float fahrenheit = (celcius*1.8) + 32;

display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(15,5);
display.print("Vej temp:");
display.setTextSize(2);
display.setTextColor(BLACK);
display.setCursor(15,25);
display.print(celcius, 1);// - temp fra infrarød
//display.print("10*");
display.setTextSize(1);
display.setCursor(63,23);
display.print("o");
display.display();
}

void luftTemp1()
{
display.clearDisplay();
float tempNTC = temp.getTemp();
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(15,5);
display.print("Luft temp:");
display.setTextSize(2);
display.setTextColor(BLACK);
display.setCursor(15,25);
display.print(tempNTC, 1);
display.setTextSize(1);
display.setCursor(63,23);
display.print("o");
display.display();

}

void distance1()
{
display.clearDisplay();

float radius = 0.35; //meter. Dette skal brugeren selv skrive ind fra skaermen.
float hjulomkreds = 3.14 * (radius*2);


reedVal = digitalRead(reed);//get val of A0



if(reedVal == 1 && counter == 1)
{
counter = 0;

start = millis();

}
if(reedVal == 0 && counter == 0)
{

counter = 2;
}


if(reedVal == 1 && counter == 2)
{
finished = millis();
elapsed = (finished - start);
array[1] = elapsed;
tid = array[1];

counter = 0;
start = millis();
distance = distance + hjulomkreds;
}
delay(200);

//float hastighed = ((hjulomkreds * 3600)/tid); // Km/t
float hastighed = ((hjulomkreds/tid)*3600);




display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(15,5);
display.print("Distance:");
display.setTextSize(2);
display.setTextColor(BLACK);
display.setCursor(20,25);
display.print(distance/1000); // - distance fra sensor
display.display();
//display.print("10 km");
}


void fart1()
{
display.clearDisplay();

float radius = 0.35; //meter. Dette skal brugeren selv skrive ind fra skaermen.
float hjulomkreds = 2 * 3.14 * radius*radius;


reedVal = digitalRead(reed);//get val of A0



if(reedVal == 1 && counter == 1)
{
counter = 0;

start = millis();

}
if(reedVal == 0 && counter == 0)
{

counter = 2;
}


if(reedVal == 1 && counter == 2)
{
finished = millis();
elapsed = (finished - start);
array[1] = elapsed;
tid = array[1];

counter = 0;
start = millis();
distance = distance + 0.35;
}
delay(200);


float hastighed = ((hjulomkreds/tid)*3600);


display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(15,5);
display.print("Hastighed:");
display.setTextSize(2);
display.setTextColor(BLACK);
display.setCursor(1,25);
display.print(hastighed, 1); // - farten fra sensor
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(53,32);
display.print("km/t");
display.display();
//display.print("25 km/t");
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////










////////////////////////////////// START SKÆRM //////////////////////////////////////////////////////
void skaermSetup1()
{
ur();
luftTemp();
vejTemp();
fart();
distance2();
display.display();
display.clearDisplay();
}
////////////////////////////////////////////////////////////////////////////////////////










//////////////////////////////////// SETUP AF SKÆRM ////////////////////////////////////////////////////
void setup()
{
i2c_init(); //Initialise the i2c bus
PORTC = (1 << PORTC4) | (1 << PORTC5);//enable pullups
pinMode(25, OUTPUT);
pinMode(12, INPUT_PULLUP);
pinMode(22, OUTPUT);
pinMode(24, OUTPUT);
pinMode(26, OUTPUT);
Serial.begin(9600);

display.begin();
display.setContrast(50);
display.setRotation(2);
display.display(); // show splashscreen
delay(2000);
display.clearDisplay(); // clears the screen and buffer
}
////////////////////////////////////////////////////////////////////////////////////////











////////////////////////////////////BUZZER//////////////////////////////////
void ylyd()
{
tone(8, NOTE_C4, 300);
delay(500);
tone(8, NOTE_C4, 300);
delay(1000);
countLyd=0;
}


void rlyd()
{
tone(8, NOTE_C4, 300);
delay(500);
tone(8, NOTE_C4, 300);
delay(500);
tone(8, NOTE_C4, 300);
delay(500);
tone(8, NOTE_C4, 300);
delay(500);
tone(8, NOTE_C4, 300);
delay(1000);
countLyd=1;
}
//////////////////////////////////////////////////////////////////////////////











void loop()
{
float tempNTC = temp.getTemp();

int dev = 0x5A<<1;
int data_low = 0;
int data_high = 0;
int pec = 0;

i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x07);

// read
i2c_rep_start(dev+I2C_READ);
data_low = i2c_readAck(); //Read 1 byte and then send ack
data_high = i2c_readAck(); //Read 1 byte and then send ack
pec = i2c_readNak();
i2c_stop();

//This converts high and low bytes together and processes temperature, MSB is a error bit and is ignored for temps
double tempFactor = 0.02; // 0.02 degrees per LSB (measurement resolution of the MLX90614)
double tempData = 0x0000; // zero out the data
int frac; // data past the decimal point

// This masks off the error bit of the high byte, then moves it left 8 bits and adds the low byte.
tempData = (double)(((data_high & 0x007F) << 8) + data_low);
tempData = (tempData * tempFactor)-0.01;

float celcius = tempData - 273.15;
float fahrenheit = (celcius*1.8) + 32;










/////////////////////////////////////// DET MED KNAPPER ///////////////////////////////////////////////

int knapVal = digitalRead(12);

if (knapVal == LOW & buttonState ==1)
{
count = count+1;
buttonState = 2;
}

if (knapVal == HIGH & buttonState ==2)
{
buttonState =1;
}

if(count==0)
{
skaermSetup1();

}
if(count==1){
display.clearDisplay();
ur1();
display.display();
}

if(count==2){
display.clearDisplay();
vejTemp1();
display.display();
}

if(count==3){
display.clearDisplay();
luftTemp1();
display.display();
}

if(count==4){
display.clearDisplay();
fart1();
display.display();
}

if(count==5){
display.clearDisplay();
distance1();
display.display();
}

if(count==6)
{
count=0;
}
////////////////////////////////////////////////////////////////////////////////////////











////////////////////////////////// DET MED LYS //////////////////////////////////////////////////////
if(tempNTC < 26 || celcius < 26) // ændres til 0 og 0
{
lysR();

if (countLyd==0)
{
rlyd();
}
}


else if(tempNTC > 30 && celcius < 30)
{
lysY();
if (countLyd==1 || countLyd==2)
{
ylyd();
}
}

else if(tempNTC < 30 && celcius > 30)
{
lysY();
if (countLyd==1 || countLyd==2)
{
ylyd();
}
}

else if(tempNTC < 30 && celcius < 30 && celcius > 26 && tempNTC > 26) // ændres til 2 og 2 og 0 og 0
{
lysY();
if ((countLyd==1 || countLyd==2))
{
ylyd();
}
}

else if(tempNTC > 30 && celcius > 30) // ændres til 2 og 2
{
lysG();
countLyd=2;
}
////////////////////////////////////////////////////////////////////////////////////////

}// LOOP END

最佳答案

我很确定你的问题出在这一行,但很难知道,因为你没有说编译器在哪一行给你错误:

while (i<STR)

这是因为你这样做:

#define STR 100;

预处理器会将其更改为:

while (i<100;)

这不是 C 中的有效表达式。

关于c - Arduino (C) - "expected primary-expression before ' )',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27293764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com