Pages: [1]   Go Down
Author Topic: Problem with ir remote library and pwm pins  (Read 685 times)
0 Members and 1 Guest are viewing this topic.
India
Offline Offline
Newbie
*
Karma: 0
Posts: 3
newbie in arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I am a newbie in arduino. I want to control the brightness of the led using ir remote. But this doesn't work. I am using irremote.h library.

I think the problem is related to timers. What I have to do???

The code is given below..
Code:

#include <IRremote.h>

int ir_pin = 3;
int pwm_signal=11;
int value;
int x;
int i = 0;
unsigned long start;
unsigned long stp;

IRrecv irrecv (ir_pin);
decode_results results;

void setup()
{
 Serial.begin(9600);
 irrecv.enableIRIn();
 pinMode(pwm_signal,OUTPUT);
  
}

void loop()
{
  x = ir_check();
  pwm_write (x);
 Serial.println(x);
}

int ir_check()
{
  if (irrecv.decode(&results))
  {
    if (results.value==2060 || results.value==12)
    {
      Serial.println("on");
      i++;
    }
    irrecv.resume();
  }
 
  return i;
}

void pwm_write (int x)
{
  if (x<10)
  {
    value = x*24;
  }  
   /* digitalWrite(pwm_signal,HIGH);
    delayMicroseconds(value);
    digitalWrite(pwm_signal,LOW);
    delayMicroseconds(1000-value);*/
   analogWrite(pwm_signal,value);
  
 
}
  
     
      
      
    
    
  
« Last Edit: February 09, 2013, 03:02:09 pm by shihtin » Logged

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19314
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Read this before posting a programming question


Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

India
Offline Offline
Newbie
*
Karma: 0
Posts: 3
newbie in arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the information... can you give any solution?. I am using arduino dueminalove.
Logged

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19314
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What does your debugging display tell you?

Perhaps put in more serial prints to confirm what values you have in your variables.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

India
Offline Offline
Newbie
*
Karma: 0
Posts: 3
newbie in arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It work well till first key is pressed on irremote. After that both ir and pwm functions remains in previous condition. I think the problem is related to the timer of the arduino dueminalove. ie, both ir library and analogWrite function uses the same library. I tried to change the timer used in ir library but it can't create any difference.
Logged

Pages: [1]   Go Up
Jump to: