Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Turning led on and off remotelly on: October 07, 2012, 04:27:08 pm

This is best I can make. The led turns on and off in intervals, only the on interval is much longer then off. I'm quite sure that the problem is speed, because state in between two consecutive 0xF is the same as the state when button is released. I think it could be solved with some timers included and to tell the arduino that it should turn led off only if it has passed enough time from last command, and to reset that timer when program receives 0xF again. But i don't know how to include timers in whole story.

Here is the program i've build so far using all your recommendations. Thanks for solutions so far  smiley-mr-green

Code:
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

unsigned long value;


void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(13,OUTPUT); //pin for driving the led
}

void loop() {
  static boolean key_pressed;
  int k;
  results.value = 0;
  if (irrecv.decode(&results)) {
     Serial.println(results.value, HEX);
   
     if (results.value == 0x8B712ED) {
        key_pressed = true;
     }
     if ((results.value == 0xFFFFFFFF) && key_pressed) {
      digitalWrite (13, HIGH);
     delay(400);
      k = 1;
    }
    if (results.value != 0x8B712ED && results.value != 0xFFFFFFFF) {
     key_pressed = false;
    }
   irrecv.resume(); 
   }
   if (k == 1 && results.value == 0) {
   digitalWrite (13, LOW);
   k = 0;
   }
   }



2  Using Arduino / Programming Questions / Re: Turning led on and off remotelly on: October 07, 2012, 10:55:53 am
@bricofoy: not working..i think that problem might be in speed..processor is driving program very fast, faster than remote sends commands. So, in the gap of two 0xF commands, arduino will pass through loop many times, resulting in led13 shutdown. There should be some kind of delay i think, maybe...

@paulS

Good idea, i'll try that.

Edit: whatever i try to do except turn on by one button, and turn off by another, is not working. I really don't understand this, programming is my weak point smiley-sad
3  Using Arduino / Programming Questions / Re: Turning led on and off remotelly on: October 07, 2012, 08:38:10 am
Here's what i get when long pressed button:

8B7926D
8B7926D
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFF

then long press another button:
8B710EF
8B710EF
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFF

and another:

8B7D02F
8B7D02F
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFF
4  Using Arduino / Programming Questions / Re: Turning led on and off remotelly on: October 07, 2012, 07:41:43 am
@bricofoy:

The new code is not working, the led neither turns on or off. But the monitor prints commands arduino is receiving.

Here is the article that explains NEC type protocol.

http://wiki.altium.com/display/ADOH/NEC+Infrared+Transmission+Protocol
5  Using Arduino / Programming Questions / Re: Turning led on and off remotelly on: October 07, 2012, 06:06:27 am
You can try something like this :
Code:
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(13,OUTPUT); //pin for driving the led
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);

    if(results.value == value_for_the_key_you_want) //test what key is pressed
        digitalWrite(13,HIGH);  //turn on led if the key is pressed
    else digitalWrite(13,LOW); //turn off led if the key is not pressed

    irrecv.resume(); // Receive the next value
  }
}

Thanks but that is not what i want. You wrote a code that will turn the led on when i press button, not while i'm holding the button down. The code for short press and for holding down button are not the same, and the codes for holding down any button are the same (FFFFFFFFF), just first code differents. Let's say if i press power button, monitor prints 123456 (this code is just example) in hex, but when I hold that button for a bit longer time, monitor prints 123456 and than FFFFFFFF one bellow another. When i press another button, it displays it's code (example 123321), but when i hold that button down, it prints FFFFFFFF again. Each button has it's own code, but when the button is held down, remote sends button unique code once and FFFFFFFF as long as i'm holding the button.   
6  Using Arduino / Programming Questions / Turning led on and off remotelly on: October 07, 2012, 04:50:04 am
I downloaded the ir library and i'm having problems with controlling pin13 led by long holding certain button. I know how to make led to turn on by pressing one button, and to turn off by pressing another button, but I don't know how to program arduino to hold the led turned on while i'm holding down a button, and to turn it off when i move my finger off that button.

When a button is pressed shortly, serial monitor displays some code. When i hold button down, serial monitor prints FFFFFFFF repeatedly.

This is the example program i wan't to modify. So, i wan't to make led on pin13 on when i'm holding down a button on my remote, and to turn it off when i'm not. Thanks for assistance, i'm beginner in programming.

Code:
#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
}
Pages: [1]