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

42 views Asked by At

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?

1

There are 1 answers

0
ATP On BEST ANSWER

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