Hi everyone, I'm using 2d arrays for the first time and I'm stuck on this error:
expected primary-expression before 'int'.
In this project, I've a 2d array with 2 rows per column. The first row is the millimeters that my sensor is away from an object, and the second row is the ADC value that the sensor reads out.
What I'm trying to do here is to see which second row (ADC value) has the same value as x (my sensor readings), and then print the value of the respective first row.
Thank you for your answers.
Code:
#define sensor A0 // Sharp IR GP2Y0A41SK0F (4-30cm, analog)
void setup() {
Serial.begin(9600); // start the serial port
int y;
int nRow;
int myArray[y][nRow] = { /*All milimeters by there respective ADC value*/
{40, 506,},
{41, 496,},
{42, 487,},
{43, 481,},
{44, 471,},
{45, 465,},
{46, 457,},
{47, 449,},
{48, 442,},
{49, 434,},
{50, 428,},
{51, 422,},
{52, 414,},
{53, 408,},
{54, 406,},
{55, 397,},
{56, 391,},
{57, 385,},
{58, 381,},
{59, 373,},
{60, 369,},
{61, 362,},
{62, 358,},
{63, 354,},
{64, 346,},
{65, 342,},
{66, 340,},
{67, 336,},
{68, 328,},
{69, 324,},
{70, 319,},
{71, 317,},
{72, 313,},
{73, 309,},
{74, 305,},
{75, 301,},
{76, 299,},
{77, 295,},
{78, 291,},
{79, 287,},
{80, 283,},
{81, 279,},
{82, 274,},
{83, 270,},
{84, 268,},
{85, 266,},
{86, 262,},
{87, 260,},
{88, 256,},//////////
{89, 254,},
{90, 252,},
{91, 248,},
{92, 246,},
{93, 244,},
{94, 242,},
{95, 238,},//////////
{96, 235,},
{97, 233,},
{98, 229,},//////////
{99, 227,},
{100, 225,},
};
}
void loop() {
int y;
int x = analogRead(sensor);
// Serial.println(x);
if(int myArray[y][1] == x){
Serial.print(myArray[y][0]);
Serial.println(" milimeters");
}
delay(100);
}