试图让光敏电阻通过对 EV3 的有线命令进行模拟读数

Trying to get a photoresistor to take an analog reading through a wire command to an EV3

这是我们遇到错误的代码部分

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

如何修复错误?

问题是您已经将 measureameasure 声明为 define 宏。 不能创建同名变量。

试试这个:

   //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);
}