Go Down

Topic: "Error Compiling for Board Arduino/Genuino Uno" When I try to Run my Code (Read 203 times) previous topic - next topic

sebaswashere1

Hi,

I'm trying to make a program to test the functioning of an IR sensor that generates an array of values with the analogRead input from pin A2. While this array generates, with successive elements created with the voltage inputted by the IR sensor, a person moves a flame closer and closer to the IR sensor. In the end, successive element values should get progressively larger (as the flame is moved closer and closer to the sensor while the for loop iterates).

I posted a question earlier about this same code and received a helpful response that allowed me to fix an earlier error. Now I'm receiving a different error (in the subject above). The syntax in the code looks fine now, so I am unsure as to what is wrong. I am experienced in Java but not at all in C++, so maybe there is something that I am missing.

Here is the code:

Code: [Select]

void setup() {
  Serial.begin(9600);
  pinMode(A2, INPUT);
}

float IROne[100];
boolean result;

boolean testOne (float IROne []) {
  for (int i = 0; i < 100; i++) {
    IROne[i] = analogRead(A2);
    if (IROne[i] > IROne[i - 1]) {
      result = true;
      Serial.println(result);
    }
  }
  result = false;
  Serial.println(result);
}

alesam

Could you post a full error report?
I suspect you are missing loop() function at your code.

AWOL

Your function has no return.

Code: [Select]
if (IROne[i] > IROne[i - 1]) { Your array has no element with the index -1

sebaswashere1

Here is the full error report:

Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\sebas\AppData\Local\Temp\ccIjtXRj.ltrans0.ltrans.o: In function `main':

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/main.cpp:46: undefined reference to `loop'

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

alesam


sebaswashere1

Even after wrapping the boolean function with void loop() {}, i still get this error message:

Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\sebas\Documents\Arduino\Arduino_Practical_Quiz_Three\Arduino_Practical_Quiz_Three.ino: In function 'void loop()':

Arduino_Practical_Quiz_Three:24:36: error: a function-definition is not allowed here before '{' token

   boolean testOne (float IROne []) {

                                    ^

Arduino_Practical_Quiz_Three:37:1: error: expected '}' at end of input

 }

 ^

exit status 1
a function-definition is not allowed here before '{' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

AWOL

We can't see your code.

Sorry for pointing out this obvious fact.

Quote
Even after wrapping the boolean function with void loop() {},
This is worrying.

sebaswashere1

Ah my bad, overlooked that.

Here it is:

Code: [Select]


void setup() {
  Serial.begin(9600);
  pinMode(A2, INPUT);
}

float IROne[100];
boolean result;

void loop() {
  boolean testOne (float IROne []) {
    for (int i = 0; i < 100; i++) {
      IROne[i] = analogRead(A2);
      if (IROne[i] > IROne[i - 1]) {
        result = true;
        Serial.println(result);
      }
    }
    result = false;
    Serial.println(result);
  }
}


AWOL

You can't define a function inside another function.
Move it out of loop()

sebaswashere1

Perfect! Thanks; I'm sorry if this was agonizingly-frustrating for you. This is the first program besides an LED blinker and simple analog reader I've had to made and I'm very new to programming.

AWOL


Go Up