no repeated action until another button is pressed

Good evening,

To begin, I'm quite a beginner in writing codes. I'm trying to write something for a while now, but now I got stuck. I try to use a uno to receive ir signals from my lg magic remote ( tried for a second to decode it's 2.4ghz RF signals but that seems quite complicated as I can find on the forum), and use two buttons of it. One for lowering my tv from the ceiling for appr 6 seconds, then turning on (discrete on code), the other button to do the opposite. This works all fine, but I do not want the Arduino to respond to the on button a second time ( since it then activates my tv lift again to lower the tv even more (a not-lifetime-improving action for the lift:) ). So a sort of "only if button off pressed -> response to pressing the on button". I hope one of you can help me with this issue:) Below the code until now:

// Include IR Remote Library by Ken Shirriff
#include <IRremote.h>
#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

// Define sensor pin
const int RECV_PIN = 4;

// Define integer to remember toggle state
int togglestate = 0;

// Define IR Receiver and Results Objects
IRrecv irrecv(RECV_PIN);
decode_results results;

// Create IR Send Object
IRsend irsend;

void setup(){

Serial.begin(9600);

// Transmitter is connected to Arduino Pin #10
mySwitch.enableTransmit(10);

// Enable the IR Receiver
irrecv.enableIRIn();

}

void loop(){
if (irrecv.decode(&results)){

switch(results.value){
case 0x9001019: //on and tv down
// Turn tv down for X Seconds
mySwitch.send(1208561, 24);
delay(3000);
mySwitch.send(1208561, 24);
irsend.sendNEC(0x20DF23DCU, 32);
delay(1000);
irrecv.enableIRIn(); // Start the receiver

break;

case 0x900BCB5: //off and tv up

mySwitch.send(1208562, 24);
delay(3000);
mySwitch.send(1208562, 24);
irsend.sendNEC(0x20DFA35CU, 32);
delay(1000);
irrecv.enableIRIn(); // Start the receiver
break;

}
irrecv.resume();
}

}

Welcome to the forums. Please read the sticky post at the top of the forum about how to post your code using code tags. It will help people help you.

As for your issue, you need to remember what state you are in (up or down) and then act accordingly. To do this, create another variable and when the TV comes down set it to 1 or something. When you receive a signal, if it is the DOWN signal but the variable is already set, ignore it.

To ignore the repeat code (IRremote library versions prior to 3.0):

 if (irrecv.decode(&results))
    { 
        switch(results.value){
           case REPEAT_CODE:  // insert your repeat code
               irrecv.resume();
               return;
               break;

baswess99:
but I do not want the Arduino to respond to the on button a second time

i'm curious what the convention approach is to handling this

it seems that timestamps need to capture when an IR code is recognized as well as that none is being received for some minimum period of time for on/off operations, but also need to recognize auto-repeat if a code has continually been received for some period of time and then repeats at intervals

a flag can be set when an on/off code is received, preventing repetition. a timestamp could also be captured which when no code has been received for some interval resets the flag.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.