Arduino Forum

Using Arduino => Programming Questions => Topic started by: Henrywallace on Aug 17, 2017, 04:29 pm

Title: blink led with remote
Post by: Henrywallace on Aug 17, 2017, 04:29 pm
This is the first code ive wrote all by myself and it seems to be working but not very good.  The led seems to only turn on when i hit a button on the remote like 50 percent of the time. The rest of the time i can see that my ir sensors build in light is blinking when i hit a button but nothing happens. I wasnt sure if i have to declare the receive pin as an input or not. I also wasnt sure if i had to declare my variables and include my libraries in the setup() statement or before it. Im using a attiny 85 processor and not sure what pins can be used for what tasks. I know they all are capable digital read/write, and only some are capable of analog read and write. If anyone has any ideas to make this code better and run more smoothly please let me know.

#include <IRremote.h>
#include <IRremoteInt.h>

int RECV_PIN = 3;
int RELAY_PIN = 2;
int LED_PIN = 1;
int BLINK_PIN = 0;

bool on = 0;

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
 pinMode(RELAY_PIN, OUTPUT);
 pinMode(LED_PIN, OUTPUT);
 pinMode(BLINK_PIN, OUTPUT);
 pinMode(RECV_PIN, INPUT);
 irrecv.enableIRIn();

 digitalWrite(RELAY_PIN, LOW);
 digitalWrite(LED_PIN, LOW);
 digitalWrite(BLINK_PIN, LOW);
}

void loop() {

digitalWrite(BLINK_PIN, HIGH);
delay(250);
digitalWrite(BLINK_PIN, LOW);
delay(250);

 if (irrecv.decode(&results)) {
     on = !on;
     digitalWrite(RELAY_PIN, on ? HIGH : LOW);
     digitalWrite(LED_PIN, on ? HIGH : LOW);    
   irrecv.resume();
 }
}
Title: Re: blink led with remote
Post by: AWOL on Aug 17, 2017, 04:49 pm
There's a guy here (https://forum.arduino.cc/index.php?topic=491534.msg3353921#msg3353921) (currently enjoying a brief forum timeout for childish behaviour) with a very similar problem, and a very identical IP address.

Care to comment?

Please remember to use code tags when posting code.
Title: Re: blink led with remote
Post by: Henrywallace on Aug 17, 2017, 04:56 pm
There's a guy here (https://forum.arduino.cc/index.php?topic=491534.msg3353921#msg3353921) (currently enjoying a brief forum timeout for childish behaviour) with a very similar problem, and a very identical IP address.

Care to comment?

Please remember to use code tags when posting code.
I just read the thread you posted and couldn't find anything useful. My code is working but i just think there might be better way to code it so that it would be more consistent. Like i said its only working when i hit a button sometimes, and the rest of the time it seems like its not sending a signal from the ir sensor to the microprocessor.
Title: Re: blink led with remote
Post by: AWOL on Aug 17, 2017, 05:00 pm
Quote
Like i said its only working when i hit a button sometimes, and the rest of the time it seems like its not sending a signal from the ir sensor to the microprocessor.
I'd get rid of the delays()s
Title: Re: blink led with remote
Post by: Henrywallace on Aug 17, 2017, 05:19 pm
I'd get rid of the delays()s
Im at work right now so i cant test it out. Wouldnt that cause my BLINK_LED to flash so fast that it would just look like a flicker? Are you saying to get rid of the delay because it causing some sort of blank moment for 250 milliseconds where the microprocessor cant get signal from the ir sensor? Do you have any comment on me defining RECV_PIN as an input? I looked at some examples and they never define a pinMode() for the Ir recieve pin.
Title: Re: blink led with remote
Post by: larryd on Aug 17, 2017, 05:32 pm
Replace delay()s with the BWD technique.

https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay (https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay)




.
Title: Re: blink led with remote
Post by: AWOL on Aug 17, 2017, 05:37 pm
No, it would cause the LED to blink so fast, it just looks like it is dim.
I would assume any library using a pin would set the pinMode itself, but I haven't used the IR library for a very long time.
You could check the documentation of the library to see if it is compatible with the processor you're using (timers etc).

I'd also edit my original post, to use code tags.
Title: Re: blink led with remote
Post by: Henrywallace on Aug 17, 2017, 05:48 pm
Very useful. I think ive implemented this correctly but dont have the IDE here at work to compile it. It probably does set the pinmode automatically. Ill remove it because the example code from the library didnt have it. The only question i have now is if i should use the delay without timer in the part at the bottom where it decodes the signal? When i click a button on my ir remote, my ir sensor blinks really fast. Is there a way to add like a pause between clicks so that its only picking up me pressing the button once?
Code: [Select]
#include <IRremote.h>
#include <IRremoteInt.h>
 
int RECV_PIN = 3;
int RELAY_PIN = 2;
int LED_PIN = 1;
int BLINK_PIN = 0;

bool SIGNAL_ON = 0;
bool LED_ON = 0;

unsigned long currentMillis = millis();
unsigned long previousMillis = 0;
 
IRrecv irrecv(RECV_PIN);
decode_results results;
 
void setup()
{
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  pinMode(BLINK_PIN, OUTPUT);
  irrecv.enableIRIn();

  digitalWrite(RELAY_PIN, LOW);
  digitalWrite(LED_PIN, LOW);
  digitalWrite(BLINK_PIN, LOW);
}
 
void loop() {

 if (currentMillis - previousMillis >= 250) {

previousMillis = currentMillis;
LED_ON = !LED_ON;
digitalWrite(BLINK_PIN, LED_ON);

}

  if (irrecv.decode(&results)) {
      SIGNAL_ON = !SIGNAL_ON;
      digitalWrite(RELAY_PIN, on ? HIGH : LOW);
      digitalWrite(LED_PIN, on ? HIGH : LOW);     
    irrecv.resume();
  }

}
Title: Re: blink led with remote
Post by: AWOL on Aug 17, 2017, 05:51 pm
Quote
my ir sensor blinks really fast.
Are you sure you've wired it correctly?
Title: Re: blink led with remote
Post by: AWOL on Aug 17, 2017, 05:52 pm
Code: [Select]
void loop() {

 if (currentMillis
I think you forgot something.
Title: Re: blink led with remote
Post by: PaulS on Aug 17, 2017, 06:03 pm
Code: [Select]
      SIGNAL_ON = !SIGNAL_ON;
By convention, all capital letter names are reserved for constants. Constants do not belong on the left side of an equal sign (except when declared, to provide the constant value).
Title: Re: blink led with remote
Post by: Henrywallace on Aug 17, 2017, 06:09 pm
Are you sure you've wired it correctly?
Yes and no. On my ir sensor I have my 5v hooked up to 5v on my breadboard, ground hooked up to ground on my breadboard, and out connected to pin 0 on my microprocessor. Im just not sure if pin 0 can be used for the input that its using. I looked it up and im pretty sure the ir sensor sends digital information, not analog. All the pins on my attiny 85 are capable or digital read and write.  So yes i believe that ive wired it correctly.

AWOL i looked and dont see what i forgot. That code came straight from link the other guy posted. Maybe its something simple but i dont see it, sorry about that.

PaulS im also having trouble understanding what youre saying. Are you saying all capitals is wrong and wont work, or it will work but not typical coding context?

Btw thank you all for your help so far. Im hoping when i get off ill be able to put new code on my microprocessor and test it out.
Title: Re: blink led with remote
Post by: AWOL on Aug 17, 2017, 06:11 pm
Quote
That code came straight from link the other guy posted.
No, it didn't.
Title: Re: blink led with remote
Post by: Henrywallace on Aug 17, 2017, 06:15 pm
No, it didn't.
The line that contains

if (currentMillis - previousMillis >= interval) {

I copy and pasted that line straight from the blink without delay webpage. Im not trying to argue, i honestly just dont see what i forgot.
Title: Re: blink led with remote
Post by: AWOL on Aug 17, 2017, 06:18 pm
I didn't highlight just that line.
I did that for a reason.
Title: Re: blink led with remote
Post by: Henrywallace on Aug 17, 2017, 06:21 pm
I didn't highlight just that line.
I did that for a reason.
Oh are you talking about defining currentMillis? I defined that variable and the previousMillis variable before the setup() part of the code. Does it not work with it up there?
Title: Re: blink led with remote
Post by: PaulS on Aug 17, 2017, 06:27 pm
Quote
PaulS im also having trouble understanding what youre saying. Are you saying all capitals is wrong and wont work, or it will work but not typical coding context?
It will work, but it will cause people that follow conventions, and expect others to follow them, too, to look at you funny.
Title: Re: blink led with remote
Post by: Henrywallace on Aug 17, 2017, 06:32 pm
It will work, but it will cause people that follow conventions, and expect others to follow them, too, to look at you funny.
Okay that makes sense. So only use all capital names when its a constant? A constant is something that doesnt change like my BLINK_PIN or LED_PIN right?
Title: Re: blink led with remote
Post by: AWOL on Aug 17, 2017, 06:37 pm
Oh are you talking about defining currentMillis? I defined that variable and the previousMillis variable before the setup() part of the code. Does it not work with it up there?
Think about it - the global variables get initialised once, before your code has even thought about considering allowing the possibility of running to cross its mind.
Title: Re: blink led with remote
Post by: Henrywallace on Aug 17, 2017, 06:44 pm
Think about it - the global variables get initialised once, before your code has even thought about considering allowing the possibility of running to cross its mind.
So currentMillis cant get defined before setup because the code hasnt even begun to run yet and it hasnt started counting milliseconds? I never really thought about it like that. Can i define currentMillis and previousMillis in the Setup() function? Good catch, thank you.
Title: Re: blink led with remote
Post by: AWOL on Aug 17, 2017, 06:45 pm
Quote
Can i define currentMillis and previousMillis in the Setup() function?
Certainly.
But then they won't be in scope in loop().
Title: Re: blink led with remote
Post by: Henrywallace on Aug 17, 2017, 06:56 pm
Certainly.
But then they won't be in scope in loop().

Okay hold up, can i take back my last comment lol. Yes i just realized if i define it in setup() i wont be able to use in loop(). I also realized that it needs to be in loop so that currentMillis is constantly getting updated at the beginning of the loop.
Title: Re: blink led with remote
Post by: larryd on Aug 17, 2017, 07:03 pm
Here is a sketch from a while back that may help you to visualize some things:
Code: [Select]
 

//**********************************************************************
 
#include "IRremote.h"
//LarryD

//Sketch to demonstrate using an IR hand remote to control Arduino outputs.
//The remote used here uses the NEC protocol.
//This remote sends the button code (example 0xFF629D) then a repeat code 0xFFFFFFFF
//The repeat code is re-sent as long as an IR remote button is pressed.
//The IR receiver used is the TSOP4838
 
/*  17 IR button remote layout   http://i.imgur.com/X1KIdqI.png
 
   ^
< OK  > 
   v
1  2  3
4  5  6
7  8  9
*  0  #
 
*/
 
 
const byte RECV_PIN = 7;   //IR receive pin
 
IRrecv irrecv(RECV_PIN);   //create instance of 'IRrecv'
decode_results results;    //create instance of 'decode_results'
 
unsigned long   TimerUp;   //UP arrow on the remote
boolean         TimerUpFlag = false;
 
unsigned long   TimerDown; //DOWN arrow on the remote
boolean         TimerDownFlag    = false;
 
unsigned long   TimerIntensity;
unsigned long   TimerIncDec;
boolean         intesityUpFlag   = false;
boolean         intesityDownFlag = false;
int             brightness;
 
unsigned long   dummy;
unsigned long * TimerPtr = &dummy; //pointer to the current timer
 
const byte upLED        = 13;  //turns on as long as the UP button is pressed
const byte downLED      = 12;  //turns on as long as the DOWN button is pressed
const byte leftLED      = 11;  //toggles on/off
const byte rightLED     = 10;  //toggles on/off
const byte intensityLED =  9;  //a LED which can have its intensity adjusted
 
 
//                           s e t u p ( )
//**********************************************************************
void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); //start receive
 
  pinMode(upLED,   OUTPUT);
  pinMode(downLED, OUTPUT);
  pinMode(leftLED, OUTPUT);
  pinMode(rightLED, OUTPUT);
  pinMode(intensityLED, OUTPUT); //this is a PWM output pin
 
} //                    E N D  O F  s e t u p ( )
 
 
 
//                            l o o p ( )
//**********************************************************************
void loop()
{
  if (irrecv.decode(&results)) //is there IR remote button code
  {
    //Serial.println(results.value);
    processButton(); //process button press
    irrecv.resume(); //restart for next button press
  }
 
  //**********************                                //Turn off upLED
  //if timing is enabled, is it time to stop
  if (TimerUpFlag && millis() - TimerUp >= 250ul)
  {
    TimerUpFlag = false; //disable timing
    TimerPtr = &dummy;   //pointer to dummy timer
    digitalWrite(upLED, LOW);
  }
 
  //**********************                                //Turn off downLED
  //if timing is enabled, is it time to stop
  if (TimerDownFlag && millis() - TimerDown >= 250ul)
  {
    TimerDownFlag = false; //disable timing
    TimerPtr = &dummy;     //pointer to dummy timer
    digitalWrite(downLED, LOW);
  }
 
  //**********************                                //LED intensity
  //are we still within the adjustment time
  if (millis() - TimerIntensity <= 300ul)
  {
    //is it time to increase/decrease the intensity
    if (millis() - TimerIncDec >= 200ul)
    {
      TimerIncDec = millis();
 
      if (intesityUpFlag == true) //Increase
      {
        brightness += 5;
        if (brightness > 255)
        {
          brightness = 255;
        }
      }
      else if (intesityDownFlag == true) //Decrease
      {
        brightness -= 5;
        if (brightness < 0)
        {
          brightness = 0;
        }
      }
 
      analogWrite(intensityLED, brightness);
      //Serial.println(brightness); //debug
    }
  }
  //stop increasing/decreasing intensity
  else
  {
    intesityUpFlag = false;
    intesityDownFlag = false;
  }
 
  //************************************
  //Other non blocking code goes here
  //************************************
 
} //                   E N D  O F  l o o p ( )
 
 
 
//======================================================================
//                       F U N C T I O N S
//======================================================================
 
//                   p r o c e s s B u t t o n ( )
//**********************************************************************
//process IR remote button presses
void processButton()
{
  switch (results.value)
  {
    //**********************
    case 0xFF629D:                                           //UP Arrow
      {
        Serial.println("UP");
        TimerPtr = &TimerUp;  //point to this timer
        TimerUpFlag = true;   //enable timing
        digitalWrite(upLED, HIGH);
        TimerUp = millis();
      }
      break;
 
    //**********************
    case 0xFFA857:                                           //DOWN Arrow
      {
        Serial.println("DOWN");
        TimerPtr = &TimerDown;  //point to this timer
        TimerDownFlag = true;   //enable timing
        digitalWrite(downLED, HIGH);
        TimerDown = millis();
      }
      break;
 
    //**********************
    case 0xFF22DD:                                           //LEFT Arrow
      {
        Serial.println("LEFT");
        digitalWrite(leftLED, !digitalRead(leftLED));   //Toggle LED
      }
      break;
 
    //**********************
    case 0xFFC23D:                                           //RIGHT Arrow
      {
        Serial.println("RIGHT");
        digitalWrite(rightLED, !digitalRead(rightLED)); //Toggle LED
      }
      break;
 
    //**********************
    case 0xFF42BD:                                           // * button
      {
        Serial.println("*");
        TimerPtr = &TimerIntensity;  //point to this timer
        intesityUpFlag = true;       //enable intensity up adjustment
        intesityDownFlag = false;
        TimerIncDec = millis();
        TimerIntensity = millis();
      }
      break;
 
    //**********************
   case 0xFF52AD:                                           // # button
      {
        Serial.println("#");
        TimerPtr = &TimerIntensity;  //point to this timer
        intesityDownFlag = true;     //enable intensity down adjustment
        intesityUpFlag = false;
        TimerIncDec = millis();
        TimerIntensity = millis();
      }
      break;
 
    //**********************
    case 0xFF02FD:
      Serial.println("OK");
      break;
 
    //**********************
    case 0xFF6897:
      Serial.println("1");
      break;
 
    //**********************
    case 0xFF9867:
      Serial.println("2");
      break;
 
    //**********************
    case 0xFFB04F:
      Serial.println("3");
      break;
 
    //**********************
    case 0xFF30CF:
      Serial.println("4");
      break;
 
    //**********************
    case 0xFF18E7:
      Serial.println("5");
      break;
 
    //**********************
    case 0xFF7A85:
      Serial.println("6");
      break;
 
    //**********************
    case 0xFF10EF:
      Serial.println("7");
      break;
 
    //**********************
    case 0xFF38C7:
      Serial.println("8");
      break;
 
    //**********************
    case 0xFF5AA5:
      Serial.println("9");
      break;
 
    //**********************
    case 0xFF4AB5:
      Serial.println("0");
      break;
 
    //**********************
    case 0xFFFFFFFF: //Repeat code
      {
        Serial.println("REPEAT");
        *TimerPtr = millis();       //reset the current timer
      }
      break;
 
  } // END switch case
 
} //             E N D  o f  p r o c e s s B u t t o n ( )
 
//**********************************************************************
 
//======================================================================
//                        E N D  O F  C O D E
//======================================================================

Title: Re: blink led with remote
Post by: Henrywallace on Aug 17, 2017, 07:09 pm
larryd ill have to read through that later when im off work, but thank you im sure ill find it useful. Here is my latest and greatest code if anyone cares and has been following along.

Code: [Select]
#include <IRremote.h>
#include <IRremoteInt.h>
 
int RECV_PIN = 0;
int RELAY_PIN = 1;
int LED_PIN = 2;
int BLINK_PIN = 3;

bool signal_on = 0;
bool led_on = 0;

unsigned long previousMillis = 0;
 
IRrecv irrecv(RECV_PIN);
decode_results results;
 
void setup()
{
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  pinMode(BLINK_PIN, OUTPUT);
  pinMode(RECV_PIN, INPUT);
  irrecv.enableIRIn();

  digitalWrite(RELAY_PIN, LOW);
  digitalWrite(LED_PIN, LOW);
  digitalWrite(BLINK_PIN, LOW);
}
 
void loop() {


unsigned long currentMillis = millis();

 if (currentMillis - previousMillis >= 250) {

previousMillis = currentMillis;
led_on = !led_on;
digitalWrite(BLINK_PIN, led_on);

}

  if (irrecv.decode(&results)) {
      signal_on = !signal_on);
      digitalWrite(RELAY_PIN, signal_on ? HIGH : LOW);
      digitalWrite(LED_PIN, signal_on ? HIGH : LOW);     
    irrecv.resume();
  }

}
Title: Re: blink led with remote
Post by: PaulS on Aug 17, 2017, 07:10 pm
Quote
Here is my latest and greatest code if anyone cares and has been following along.
You didn't compile that, did you?
Title: Re: blink led with remote
Post by: Henrywallace on Aug 17, 2017, 07:15 pm
You didn't compile that, did you?
No i cant do it at work because i dont have the IDE here. Ive been editing it in notepad and then email it to myself so i can have it when i get home. Is there another obvious thing wrong lol?
Title: Re: blink led with remote
Post by: larryd on Aug 17, 2017, 07:27 pm
 signal_on = !signal_on);



.
Title: Re: blink led with remote
Post by: Henrywallace on Aug 17, 2017, 07:48 pm
signal_on = !signal_on);



.
Just to make sure we are on the same page. Take out the extra ) after !signal_on?
Title: Re: blink led with remote
Post by: larryd on Aug 17, 2017, 08:17 pm
signal_on = !signal_on);

This should be:

signal_on = !signal_on;

Title: Re: blink led with remote
Post by: larryd on Aug 17, 2017, 08:28 pm
These are not good pins to use as they are connected to RX TX

int RECV_PIN  = 0;
int RELAY_PIN = 1;

Consider using these:

int RECV_PIN  = 2;
int RELAY_PIN = 3;
int LED_PIN   = 4;
int BLINK_PIN = 5;


Most remotes (NEC) I have used, send a repeat code (0xFFFFFFFF) after the switch code.

I your remote does this, you may want to filter the repeat code out.



digitalWrite(RELAY_PIN, signal_on ? HIGH : LOW);
digitalWrite(LED_PIN, signal_on ? HIGH : LOW);

Why not?

digitalWrite(RELAY_PIN, signal_on);
digitalWrite(LED_PIN, signal_on);


.
Title: Re: blink led with remote
Post by: Henrywallace on Aug 17, 2017, 09:39 pm
Okay ill try those pins. The problem is that pin 5 is the reset pin on my attiny, is that going to affect anything. Im not sure how the reset pin actually works. And youre right about using

digitalWrite(RELAY_PIN, signal_on);
digitalWrite(LED_PIN, signal_on);

the example code i based my work off of showed it the other way but that seems way more complicated.
Title: Re: blink led with remote
Post by: larryd on Aug 17, 2017, 09:59 pm
I don't have an attiny, pick the pins you want.



.
Title: Re: blink led with remote
Post by: Henrywallace on Aug 17, 2017, 10:02 pm
These are the pins. Any ideas which ones would be best to use?
Title: Re: blink led with remote
Post by: larryd on Aug 17, 2017, 10:05 pm
(http://qqtrading.com.my/image/catalog/Products/Arduino/ATTINY85/ATtiny85-dev-board-pinout-bid.jpg)

I plead ignorance, as mentioned don't have a tiny. :(
Title: Re: blink led with remote
Post by: larryd on Aug 17, 2017, 10:07 pm
Looks like 0,1,2,5  might be okay.


.
Title: Re: blink led with remote
Post by: Henrywallace on Aug 17, 2017, 10:16 pm
Looks like 0,1,2,5  might be okay.


.
Sorry. I tried to link the image the first time but it looks like it didnt work so i just attatched an image of it on my last post. So a pin layout like this should be correct?


int RECV_PIN = 0;
int RELAY_PIN = 1;
int LED_PIN = 2;
int BLINK_PIN = 5;
Title: Re: blink led with remote
Post by: larryd on Aug 17, 2017, 10:21 pm
You will just have to try it.


.
Title: Re: blink led with remote
Post by: Henrywallace on Aug 17, 2017, 10:26 pm
I definitely will. Im off in 2 hours. I will let you know how it works so you know, also so future people know how to fix the problem.
Title: Re: blink led with remote
Post by: Henrywallace on Aug 18, 2017, 05:42 pm
I went home and had a couple issues but here is the final code that worked perfectly. I will be making a final version without the two leds so it just controls the leds. They were only there for testing purposes but now i am working on the final copy. I will be starting another project today and hope to finish it by the end of the weekend. It will have to do with IR control of a motor. Look for my thread in the forums if youre interested.

Code: [Select]
#include <IRremote.h>
#include <IRremoteInt.h>
int RECV_PIN = 0;
int RELAY_PIN = 1;
int LED_PIN = 2;
int BLINK_PIN = 4;
int ON_TIME = 10000;

bool signal_on = 0;
bool led_on = 0;

unsigned long previousMillis = 0;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  pinMode(BLINK_PIN, OUTPUT);
  pinMode(RECV_PIN, INPUT);
  irrecv.enableIRIn();

  digitalWrite(RELAY_PIN, LOW);
  digitalWrite(LED_PIN, LOW);
  digitalWrite(BLINK_PIN, LOW);
}
void loop() {


  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= 250) {

    previousMillis = currentMillis;
    led_on = !led_on;
    digitalWrite(BLINK_PIN, led_on);

  }

  if (irrecv.decode(&results)) {
    signal_on = !signal_on;
    digitalWrite(RELAY_PIN, signal_on ? HIGH : LOW);
    digitalWrite(LED_PIN, signal_on ? HIGH : LOW);
    irrecv.resume();
  }

}
Title: Re: blink led with remote
Post by: larryd on Aug 18, 2017, 08:53 pm
FYI
If a remote sends a repeat code after an initial code, use this to ignore the repeat code.

Code: [Select]
 if (irrecv.decode(&results))
  {
    if (results.value != 0xFFFFFFFF) //NEC repeat code
    {
      signal_on = !signal_on;
      digitalWrite(RELAY_PIN, signal_on);
      digitalWrite(LED_PIN, signal_on);
    }
    
    irrecv.resume();
  }





.
Title: Re: blink led with remote
Post by: Henrywallace on Aug 18, 2017, 09:49 pm
FYI
If a remote sends a repeat code after an initial code, use this to ignore the repeat code.

Code: [Select]
if (irrecv.decode(&results))
  {
    if (results.value != 0xFFFFFFFF) //NEC repeat code
    {
      signal_on = !signal_on;
      digitalWrite(RELAY_PIN, signal_on);
      digitalWrite(LED_PIN, signal_on);
    }
   
    irrecv.resume();
  }


Illl try that because sometimes if i dont quickly press the button and i hold it for a second it will flicker on then off. I just didnt think it was a big deal because i usually just quick click the button. Thank you for that help.


.