IRremote libs conflicting with... everything...

So I'm still a newbie to the whole arduino scene, so I've started off with some starters kits.

So I've set up some LEDs, a piezo speaker to produce tones, LDR etc.

So I thought, let's try the IR sensor. So I started off, and it gave me a compile error (something with the IRremoteTools.cpp on line 5), a Google search revealed that this was some kind of demo project, so by removing this the issue should be solved.
But, because I'm using the tone() function in my project, it still wouldn't compile, so I uncommented the lines that used this function, and now it would compile, and the IR works nicely.

But, now my fading LED doesn't work anymore... Two simple for loops fading it in and out (analogeWrite() on PIN 11), the LED does blink for a brief moment (probably when it's at 255), and finishes the loop without fading out.

So am I doing something wrong? Or any solutions on how to get this (useless) setup to work the way I want it?

So am I doing something wrong?

As far as getting help the answer is yes. Post an example of a non working here explaining what it should do, what it actually does and copy any errors from the error window and paste that here too.

Read at least the first post in this thread first Read this before posting a programming question ... - Programming Questions - Arduino Forum

Sorry that's pretty obvious, but I thought it was a general issue with the libraries since I did find a lot about the issues that I already resolved...

#include <IRremote.h>

// Declaring pins
const int irPin = 4;
const int Button = 11;
const int LED = 13;

// Setting some vars for the IR
IRrecv irrecv(irPin);
decode_results results;


void setup() {
  // Preparing IR
  irrecv.enableIRIn(); // When I introduce this line the issue starts
  
  // Setting the pins
  pinMode(irPin, INPUT);
  pinMode(Button, INPUT);
  pinMode(LED, OUTPUT);
}

void loop() {
  // A loop that fades in whenever the button is pressed
  if (Button == HIGH) {
    for (i=0; i<255; I++) {
      analogWrite(LED, i);
      delay(10);
    }
   // And then there is the fade out, just a reversed version of this loop of course.
  }
}

So when I introduce the line (where I commented), the LED fade stops working. It does get into the loop, but the LED won't fade, it just blinks when it is at 255, then it turns off and finishes the second loop until it reaches 0.

I already resolved the tone() issue by using a different library (NewTone())...

void loop() {
  // A loop that fades in whenever the button is pressed
  if (Button == HIGH) {
    for (i=0; i<255; I++) {
      analogWrite(LED, i);
      delay(10);
    }

Button will always equal 11 in your program because you are not reading the current value of the Button pin with digitalRead()
The for loop will not run because i has not been declared

I'm sorry, I quickly wrote this example and forgot the digitalRead(), so that's not the issue... Like I said, the LED does blink for a brief moment, and if I remove the line that I commented, the LED does fade when I press the button...

Edit: And the example will probably fail since I didn't declare the i as an int(), but let's pretend it's there :slight_smile:

Oh, and there are no errors when I compile...

Can I suggest that you post the actual code that you are running rather than a version of it ?

For instance there are other problems with the code that you posted such as inconsistent variable names in the for loop, neither of which are declared and we don't actually know how and where you are reading the button pin nor how it is wired.

Let's pretend that you did not post the program and start again. DO NOT post a new version by editing the first post as it makes a nonsense of the replies.

It's just some play code, so some things might be written a bit funny, maybe that's the issue... Well here it is:

#include <IRremote.h>
#include <NewTone.h>

const int irPin = 4;

IRrecv irrecv(irPin);
decode_results results;

const int RLED = 13;
const int GLED = 11;
const int YLED = 10;
const int Button1 = 3;
const int Button2 = 2;
const int Speaker = 12;
int i = 0;

// Mario sound functions
int length = 295; // the number of notes
char notes[] = "EE E CE G  g  C  g e  a b ia gEGA FG E CDb C  g e  a b ia gEGA FG E CDb  GNFR E uaC aCD GNFR E 1 11   GNFR E uaC aCD L  D C   CC C CD EC ag  CC C CDE  CC C CD EC ag  EE E CE G  g  C  g e  a b ia gEGA FG E CDb C  g e  a b ia gEGA FG E CDb EC g u aF Fa  bAAAGFEC ag  EC g u aF Fa  bF FFEDCe ec  "; // a space represents a rest
float beats[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, //Page 1
                2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 2, 4, //Page 2
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, //Page4
                1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, //Page 5
                1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1.3, 1.3, 1.3, 1, 1, 1, 1, 1, 1, 2 }; //Page 6
                
int tempo = 95;
int l = 0; // LED control during musid

void playTone(int ton1, int duration) {
  for (long i = 0; i < duration * 1000L; i += ton1) {
    switch (l) {
      case 0:
      digitalWrite(GLED, LOW);
      digitalWrite(YLED, HIGH);
      l++;
      break;
      case 1:
      digitalWrite(YLED, LOW);
      digitalWrite(RLED, HIGH);
      l++;
      break;
      case 2:
      digitalWrite(RLED, LOW);
      digitalWrite(GLED, HIGH);
      l = 0;
      break;
    }
    NewTone(Speaker, ton1);
    delayMicroseconds(ton1);
  }
  noNewTone(Speaker);
}

void playNote(char note, int duration) {
//                        c    c#   d    d#   e    f    f#   g    g#   a    a#   b
  char names[] = { ' ',  '!', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', 'D', 'E', 'F', 'G', 'A', 'B', 'i', 'N', 'R', 'u',  '1', 'L', 'k'}; // [i = b flat] [N = G flat] [R = D#] [u = g#] [1 = C oct. 5] [L = E flat]
  int tones[] =  {   0, 1046, 138, 146, 155, 164, 174, 184, 195, 207, 220, 233, 246, 261, 293, 329, 349, 391, 440, 493, 523, 587, 659, 698, 783, 880, 987, 466, 740, 622, 415, 1046, 622u, 227};
  
  // play the tone corresponding to the note name
  for (int i = 0; i < 34; i++) {
    if (names[i] == note) {
      playTone(tones[i], duration);
    }
  }
}
// End of Mario sound functions

void setup()
{
  irrecv.enableIRIn();
  
  pinMode(RLED, OUTPUT);
  pinMode(GLED, OUTPUT);
  pinMode(YLED, OUTPUT);
  pinMode(Button1, INPUT);
  pinMode(Button2, INPUT);
  pinMode(Speaker, OUTPUT);
   
  // Check output connections
  digitalWrite(RLED, HIGH);
  delay(50);
  digitalWrite(RLED, LOW);
  digitalWrite(GLED, HIGH);
  delay(50);
  digitalWrite(GLED, LOW);
  digitalWrite(YLED, HIGH);
  delay(50);
  digitalWrite(YLED, LOW);
  NewTone(Speaker, 1000, 50);
  
  
  //Serial.begin(9600);
}

void loop()
{
  if (irrecv.decode(&results)) {
    //Serial.println(results.value);
    if (results.value == 16767015)
    {
      digitalWrite(GLED, HIGH);
      delay(200);
    }
    if (results.value == 16726215)
    {
      digitalWrite(YLED, HIGH);
      delay(200);
    }
    if (results.value == 16750695)
    {
      digitalWrite(RLED, HIGH);
      delay(200);
    }
    if (results.value == 16748655)
    {
      for (int i = 0; i < length; i++) {
        if (notes[i] == ' ') {
          delay(beats[i] * tempo); // rest
        } else {
          playNote(notes[i], beats[i] * tempo);
        }
      
        // pause between notes
        delay(tempo / 4);
      }
    }

    irrecv.resume();
  }
  
  int value = analogRead(5);
  if (value <= 50)
  {
    digitalWrite(YLED, HIGH);
  }else{
    digitalWrite(YLED, LOW);
  }
  
  
  if (digitalRead(Button1) == HIGH && digitalRead(Button2) == LOW)
  {
    digitalWrite(RLED, HIGH);
  }else{
    digitalWrite(RLED, LOW);
  }
  
  if (digitalRead(Button2) == HIGH && digitalRead(Button1) == LOW)
  {
    for (i=0; i<255; i++)
    {
      analogWrite(GLED, i);
      delay(5);
      if (digitalRead(Button1) == HIGH) 
      {
        break;
      }
    }
    for (i=255; i>0; i--)
    {
      analogWrite(GLED, i);
      delay(5);
      if (digitalRead(Button1) == HIGH) 
      {
        break;
      }
    }
  }else{
    digitalWrite(GLED, LOW);
  }
  
  if (digitalRead(Button1) == HIGH && digitalRead(Button2) == HIGH)
  {
    digitalWrite(RLED, HIGH);
    digitalWrite(GLED, LOW);
    NewTone(Speaker, 2000, 250);
    delay(250);
    digitalWrite(GLED, HIGH);
    digitalWrite(RLED, LOW);
    NewTone(Speaker, 1000, 250);
    delay(250);
  }
}

Everything is wired correctly, every single thing works, except for the fading, again only when I introduce the one line in the setup() function...