I need help :o

Hello,
I am sorry if I am on the wrong thread but this was the most accurate thread I could find. I am having some trouble compiling my code. It involves 4 microphones, 4 LED-lights and an IR-remote. At first it wouldn't compile because I didn't have the correct files in my library, but now I do and that problem is solved. Now it just says something is wrong and I have no clue on what it can be (I don't program a lot). Would be awesome if you have a look at my code and spot any compiling-flaws, thank you!

//Example code for detecing sound via microphone

#include <IRremote.h>
const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;
int micA0=A0; //Assign mic to analog port A0
int micA0min=0; //Define variabel for mic input minimum
int micA0max=0; //Define variabel for mic input maximum
int micA0diff=0; //Define variabel for mic input difference
int micA0tmp=0; //Define variabel for mic input temporary
int ledA0=12; //Assign led digital port 12

int micA1=A1; //Assign mic to analog port A1
int micA1min=0; //Define variabel for mic input minimum
int micA1max=0; //Define variabel for mic input maximum
int micA1diff=0; //Define variabel for mic input difference
int micA1tmp=0; //Define variabel for mic input temporary
int ledA1=11; //Assign led digital port 11

int micA2=A2; //Assign mic to analog port A2
int micA2min=0; //Define variabel for mic input minimum
int micA2max=0; //Define variabel for mic input maximum
int micA2diff=0; //Define variabel for mic input difference
int micA2tmp=0; //Define variabel for mic input temporary
int ledA2=10; //Assign led digital port 10

int micA3=A3; //Assign mic to analog port A3
int micA3min=0; //Define variabel for mic input minimum
int micA3max=0; //Define variabel for mic input maximum
int micA3diff=0; //Define variabel for mic input difference
int micA3tmp=0; //Define variabel for mic input temporary
int ledA3=9; //Assign led digital port 9

int led1=8; //Assign led digital port

// The setup function runs once when you press reset or power the board
void setup() {
Serial.begin(9600); //Serial initialization
pinMode(ledA0,OUTPUT); //Set LED ports to output
pinMode(ledA1,OUTPUT); //Set LED ports to output
pinMode(ledA2,OUTPUT); //Set LED ports to output
pinMode(ledA3,OUTPUT); //Set LED ports to output
irrecv.enableIRIn();
irrecv.blink13(true);
pinMode(led1,OUTPUT);

}

// The loop function runs over and over again forever
void loop() {
if (irrecv.decode(&results)){
Serial.println(results.value);
if (results.value == 2|results.value == 2050){ // The specific value can be found using serial monitor
digitalWrite(led1,HIGH);
Serial.println("LED ON");
}
if (results.value == 1|results.value == 2049){ // The specific value can be found using serial monitor
digitalWrite(led1,LOW);
Serial.println("LED OFF");
}
irrecv.resume();
}
delay(50);

micA0max=0;
micA0min=400;
micA1max=0;
micA1min=400;
micA2max=0;
micA2min=400;
micA3max=0;
micA3min=400;
for(int n=0;n<10;n++){
micA0tmp=analogRead(micA0); //Read analog port where mic is connected
if(micA0tmp>micA0max){ //Find max value during the loop
micA0max=micA0tmp;
}
if(micA0tmp<micA0min){ //Find min value during the loop
micA0min=micA0tmp;
}
//delay(0.1); // Wait so the Arduino has time to do analog reading (takes 100us)
micA1tmp=analogRead(micA1); //Read analog port where mic is connected
if(micA1tmp>micA1max){ //Find max value during the loop
micA1max=micA1tmp;
}
if(micA1tmp<micA1min){ //Find min value during the loop
micA1min=micA1tmp;
}
//delay(0.1);

micA2tmp=analogRead(micA2); //Read analog port where mic is connected
if(micA2tmp>micA2max){ //Find max value during the loop
micA2max=micA2tmp;
}
if(micA2tmp<micA2min){ //Find min value during the loop
micA2min=micA2tmp;
}
micA3tmp=analogRead(micA3); //Read analog port where mic is connected
if(micA3tmp>micA3max){ //Find max value during the loop
micA3max=micA3tmp;
}
if(micA3tmp<micA3min){ //Find min value during the loop
micA3min=micA3tmp;
}
} //End of inner for-loop

micA0diff=micA0max-micA0min; //Calculate signal max-min difference
micA1diff=micA1max-micA1min; //Calculate signal max-min difference
micA2diff=micA2max-micA2min; //Calculate signal max-min differenc
micA3diff=micA3max-micA3min; //Calculate signal max-min differenc

Serial.print(micA0diff); //Send mic input data to serial plotter or monitor
Serial.print(" ");
Serial.println(micA1diff); //Send mic input data to serial plotter or monitor
Serial.print(" ");
Serial.print(micA2diff);
Serial.print(" ");
Serial.print(micA3diff);
Serial.print(" ");
delay(2);
if((micA0diff>2) && (micA0diff>micA1diff) && (micA0diff>micA2diff) && (micA0diff>micA3diff)){
krilleSpex0();
}
if((micA1diff>2) && (micA1diff>micA0diff) && (micA1diff>micA2diff) && (micA1diff>micA3diff) ){
krilleSpex1();
}
if((micA1diff>2) && (micA2diff>micA0diff) && (micA2diff>micA1diff) && (micA2diff>micA3diff) ){
krilleSpex2();
}
if((micA1diff>2) && (micA3diff>micA0diff) && (micA3diff>micA1diff) && (micA3diff>micA2diff) ){
krilleSpex3();
}

} //End of main loop

// User defined functions
void krilleSpex0(){
digitalWrite(ledA0,HIGH);
Serial.print("Mic A0");
delay(100);
digitalWrite(ledA0,LOW);
micA0max=0;
micA0min=400;
}

void krilleSpex1(){
digitalWrite(ledA1,HIGH);
Serial.print("Mic A1");
delay(100);
digitalWrite(ledA1,LOW);
micA1max=0;
micA1min=400;
}

void krilleSpex2(){
digitalWrite(ledA2,HIGH);
Serial.print("Mic A2");
delay(100);
digitalWrite(ledA2,LOW);
micA2max=0;
micA2min=400;
}
void krilleSpex3(){
digitalWrite(ledA3,HIGH);
Serial.print("Mic A3");
delay(100);
digitalWrite(ledA3,LOW);
micA3max=0;
micA3min=400;
}

What's the problem?

if (results.value == 2|results.value == 2050){

Should be ||

Thank you!
Sadly, I still get the same compilation problem :confused:

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

The complete error message contains a lot more useful information than that. Click on "Copy Error Messages" in the IDE window (bottom right) and post the result here!

And while you're at it read "How to use this forum - please read" at the top of this and every other forum which gives you lots of other useful information about how to post so that you can more easily get good answers.

Steve

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

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp: In member function 'availableForWrite':

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp:203:1: internal compiler error: Segmentation fault

}

^

Please submit a full bug report,

with preprocessed source if appropriate.

See http://gcc.gnu.org/bugs.html for instructions.

lto-wrapper.exe: fatal error: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avr-gcc returned 1 exit status

compilation terminated.

c:/program files/windowsapps/arduinollc.arduinoide_1.8.21.0_x86__mdqgnx93n4wtt/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed

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.

Don't know if this solves you problem, but a neater solution using arrays looks ab nit like this. This code should be functionally identical to yours:

#include <IRremote.h>

const byte RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;

class Mic {
  public:
    const byte micPin;      //Assign mic to analog port A0
    int min;                //Define variabel for mic input minimum
    int max;                //Define variabel for mic input maximum
    int diff;               //Define variabel for mic input difference
    int tmp;                //Define variabel for mic input temporary
    const byte ledPin;      //Assign led digital port 12

    Mic(byte attachMic, byte attachLed) :
      micPin(attachMic),
      ledPin(attachLed)
    {
      min = 0;
      max = 0;
      diff = 0;
      tmp = 0;
    }

};

const int MICS = 4; // 4 microphones

Mic mic[MICS] = {
  Mic(A0, 12),
  Mic(A1, 11),
  Mic(A2, 10),
  Mic(A3, 9)
};

const byte led1 = 8; //Assign led digital port

void setup() {
  Serial.begin(9600);            //Serial initialization
  for (int m = 0; m < MICS; m++) {
    pinMode(mic[m].ledPin, OUTPUT);         //Set LED ports to output

  }
  irrecv.enableIRIn();
  irrecv.blink13(true);
  pinMode(led1, OUTPUT);

}

// The loop function runs over and over again forever
void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value);
    if (results.value == 2 | results.value == 2050) {  // The specific value can be found using serial monitor
      digitalWrite(led1, HIGH);
      Serial.println("LED ON");
    }
    if (results.value == 1 | results.value == 2049) {  // The specific value can be found using serial monitor
      digitalWrite(led1, LOW);
      Serial.println("LED OFF");
    }
    irrecv.resume();
  }
  delay(50);

  for (int m = 0; m < MICS; m++) {
    mic[m].max = 0;
    mic[m].min = 400;
  }

  for (int n = 0; n < 10; n++) {
    for (int m = 0; m < MICS; m++) {
      mic[m].tmp = analogRead(mic[m].micPin);      //Read analog port where mic is connected
      if (mic[m].tmp > mic[m].max) {         //Find max value during the loop
        mic[m].max = mic[m].tmp;
      }
      if (mic[m].tmp < mic[m].min) {         //Find min value during the loop
        mic[m].min = mic[m].tmp;
      }
    }
  }                                    //End of inner for-loop

  for (int m = 0; m < MICS; m++) {
    mic[m].diff = mic[m].max - mic[m].min;  //Calculate signal max-min difference
  }

  for (int m = 0; m < MICS; m++) {
    Serial.print(mic[m].diff);             //Send mic input data to serial plotter or monitor
    Serial.print(" ");
  }
  delay(2);

  // find the biggest diff.
  // biggest diff needs to be > 2
  // biggest diff needs to be bigger than all other diffs - no ties permitted
  // except that it's ok if there's more than one diff with size <= 2.

  int biggestDiffMic = 0;
  int biggestDiff = mic[0].diff;
  boolean tiedForFirstPlace = false;

  for (int m = 1; m < MICS && !tiedForFirstPlace; m++) {
    if (mic[m].diff > biggestDiff) {
      biggestDiffMic = m;
      biggestDiff = mic[m].diff;
    }
    else if (mic[m].diff == biggestDiff && mic[m].diff > 2) {
      tiedForFirstPlace = true;
    }
  }

  if (!tiedForFirstPlace && biggestDiff > 2) {
    krilleSpex(biggestDiffMic);
  }
}                                    //End of main loop

// User defined functions
void krilleSpex(int m) {
  digitalWrite(mic[m].ledPin, HIGH);
  Serial.print("Mic A");
  Serial.print(m);
  delay(100);
  digitalWrite(mic[m].ledPin, LOW);
  mic[m].max = 0;
  mic[m].min = 400;
}

PontusHogberg:
Arduino:1.8.9 (Windows Store 1.8.21.0) (Windows 10)

I don't understand this compiler bug/error/whatever, but I think it's a good idea to try the build of the IDE directly downloaded from the Arduino.cc website: https://www.arduino.cc/en/Main/Software