1

I'm playing around with an IR receiver and an RGB led.

I had it up and running, until I changed around some code. The remote seeming stopped working, but after looking at the values in the Serial Monitor it appeared that the values that were being printed out weren't the same.

After playing around a bit I found that if analogWrite is run on pin 11, the value changes. Why is this so?

Code is as follows:

#include <IRremote.h>
int ir_recv_pin = 2;
IRrecv irrecv(ir_recv_pin);
decode_results results;
void setup()
{
 Serial.begin(9600);
 irrecv.enableIRIn(); 
}
void loop()
{
 if (irrecv.decode(&results)) 
 {
 //Serial.println(results.value);
 Serial.println(results.value == CH_MINUS);
 Serial.println(results.value);
 Serial.println(CH_MINUS);
 analogWrite(11, 125);
 irrecv.resume();
 }
}

Output is as such when pressing the button twice in a row (without holding the button down):

1
16753245
16753245
0
3810010651
16753245

Initially the values come out as expected (16753245), but after the analogWrite, the value changes (3810010651).

Looking at the documentation it says that pin 11 runs at 980Hz. Is this why the value changes? If so, why?

asked Dec 7, 2014 at 6:35

1 Answer 1

3

Because IRremote uses timer 2 by default, and the PWM output on pin 11 is generated via OC2A. Either edit IRremoteInt.h to use timer 1, use a pin on timer 1 for PWM, or frob OCR2A directly instead.

answered Dec 7, 2014 at 8:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.