试图让光扰动者通过电线命令对EV3进行模拟读数

发布于 2025-01-26 02:50:00 字数 1038 浏览 3 评论 0原文

这是代码的一部分,我们在

//turns on the i2c commands
#include <Wire.h>
//creates a variable called SLAVE_ADDRESS and permanently sets the value to 0x04 (register #4)
#define SLAVE_ADDRESS 0x04
#define IR1 A0
#define IR2 A1
#define prnt 
#define measure
#define measurea

void setup()
{
    Serial.begin(9600); 
    //sets the address of the Arduino
    Wire.begin(SLAVE_ADDRESS);
    //the .onRequest command will run a function when it gets a request from the EV3. 
    //In this case, it will run the requestEvent function, which is defined later in the sketch.
    Wire.onRequest(requestEvent);
    
}


int measureMap = 0;

void loop() {
int measure = analogRead(A0);
  int measurea = analogRead(A1);
measureMap = map(measure, 0, 1023, 0, 63); 

Serial.print(mapMeasure);
Serial.print ("     ");
Serail.println(measure);
Serail.println(measure1);
}

拥有变量measurea的位置上遇到错误,我们会遇到一个错误,说明

measurea
exit status 1
expected unqualified-id before '=' token

如何修复错误?

Here is the part of the code we are getting the error on

//turns on the i2c commands
#include <Wire.h>
//creates a variable called SLAVE_ADDRESS and permanently sets the value to 0x04 (register #4)
#define SLAVE_ADDRESS 0x04
#define IR1 A0
#define IR2 A1
#define prnt 
#define measure
#define measurea

void setup()
{
    Serial.begin(9600); 
    //sets the address of the Arduino
    Wire.begin(SLAVE_ADDRESS);
    //the .onRequest command will run a function when it gets a request from the EV3. 
    //In this case, it will run the requestEvent function, which is defined later in the sketch.
    Wire.onRequest(requestEvent);
    
}


int measureMap = 0;

void loop() {
int measure = analogRead(A0);
  int measurea = analogRead(A1);
measureMap = map(measure, 0, 1023, 0, 63); 

Serial.print(mapMeasure);
Serial.print ("     ");
Serail.println(measure);
Serail.println(measure1);
}

Where we have the variable measureawe get an error saying

measurea
exit status 1
expected unqualified-id before '=' token

How to fix the error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贪恋 2025-02-02 02:50:00

问题在于您已经声明suberueameasuredefine宏。
您不能用相同名称制作变量。

尝试以下操作:

   //turns on the i2c commands
#include <Wire.h>
//creates a variable called SLAVE_ADDRESS and permanently sets the value to 0x04 (register #4)
#define SLAVE_ADDRESS 0x04
#define IR1 A0
#define IR2 A1


void setup()
{
    Serial.begin(9600); 
    //sets the address of the Arduino
    Wire.begin(SLAVE_ADDRESS);
    //the .onRequest command will run a function when it gets a request from the EV3. 
    //In this case, it will run the requestEvent function, which is defined later in the sketch.
    Wire.onRequest(requestEvent);
    
}


int measureMap = 0;

void loop() {
int measure = analogRead(A0);
int measurea = analogRead(A1);
measureMap = map(measure, 0, 1023, 0, 63); 

Serial.print(mapMeasure);
Serial.print ("     ");
Serail.println(measure);
Serail.println(measure1);
}

The problem is that you already declared measurea and measure as a define macro.
You can't make a variable with the same name.

try this:

   //turns on the i2c commands
#include <Wire.h>
//creates a variable called SLAVE_ADDRESS and permanently sets the value to 0x04 (register #4)
#define SLAVE_ADDRESS 0x04
#define IR1 A0
#define IR2 A1


void setup()
{
    Serial.begin(9600); 
    //sets the address of the Arduino
    Wire.begin(SLAVE_ADDRESS);
    //the .onRequest command will run a function when it gets a request from the EV3. 
    //In this case, it will run the requestEvent function, which is defined later in the sketch.
    Wire.onRequest(requestEvent);
    
}


int measureMap = 0;

void loop() {
int measure = analogRead(A0);
int measurea = analogRead(A1);
measureMap = map(measure, 0, 1023, 0, 63); 

Serial.print(mapMeasure);
Serial.print ("     ");
Serail.println(measure);
Serail.println(measure1);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文