Increase/decrease blink with a remote

Does anyone have or seen any coding I can use and learn from that will allow me to increase and decrease flashing of LED's using 2 different buttons on a universal remote?

Many thanks.

For receiving from your IR remote:

If your remote does not send one of the four recognized protocols:

Thanks for the speedy reply.

I have all the codes for each individual button and I have the remote working with my current coding but i'm in need of some code to add that will allow me to increase/decrease the blink rate using the up/down button on the remote.

If anyone has any examples of how I would achive this that would be fantastic?

Have a look at the blink without delay example - that should point you in the right direction.

I’ve been using the blink without delay for all my other flashing patterns, but I cannot seem to work out how I would make it work so it starts at a blink interval of every 100ms then at each button press the blink increases by another 100 until it reaches a maximum of 2000.

Then the down button does the opposite.

I'm no professional at this and never will be as my profession is architectural design not programming, I’m only doing this as a personal interest/challenge so I openly admit that I’m an extreme novice that needs a helping hand!

So everyone’s help is much appreciated.

Take a look at the blink without delay code and you'll see that the blink rate is controlled by the interval variable, initially set to 1000. When you detect appropriate input from your remote, add 100 to it. Later on you can add something to cap it at 2000.

Ive been on hours now and cannot make it happen.

I think I know what I need to do but I cant seem to work out how to type the code correctly

This is part of the code I am working on and it blinks as you say at 1000.

       if (results.value == button6)
       
{
              
              unsigned long currentMillis = millis();
  
   if(currentMillis - previousMillis > interval) {
     // save the last time you blinked the LED 
    previousMillis = currentMillis;  
    

    // if the LED is off turn it on and vice-versa:
     if (ledState == LOW)
       ledState = HIGH;
     else
       ledState = LOW;
 
    // set the LED with the ledState of the variable:
     digitalWrite(10, ledState);
     digitalWrite(4, ledState);
     digitalWrite(5, ledState);
     digitalWrite(6, ledState);
     digitalWrite(7, ledState);
     digitalWrite(8, ledState);
     digitalWrite(9, ledState);
     
 
  irrecv.resume(); // Receive the next value
       }
   }

Is this the kind of coding that will tell it to increase or decrease?

      if (interval > 100) {
         interval = interval +100;
         
      if (interval < 2000) {
         interval = interval -100;

If it is, how do I make it work when button6 is pressed again?

If i'm totally barking up the wrong tree please help ha-ha :stuck_out_tongue:

Imagine "interval" has the value 200.
What will your code segment do?

I would like to think it will increase by 100 to become 300?

And then very shortly after that, what happens?

It would max at 2000 and start to decrease back down until it reaches a minimum of 200

No, immediately after being incremented from 200 to 300, it gets compared to 2000.
300 is less than 2000, so it gets decremented back down to 200.

Ahhhhh right...... So as my thinking is wrong, what is the correct way?

There may not be a correct way, but I'd define a variable called"delta", that holds either 100 or -100.
Then, "interval += delta;" is always executed if a button is pressed, and all you have to do is figure how and when to flip the value of delta. You're mostly there.

It's hard to be sure from the code fragment above, but it looks like you're only doing the blinking when you detect a key from the remote. My assumption from the OP was that you want to flash the LEDs continuously, but have two buttons on the remote that change the interval. If that's correct, just put the interval adjustment code inside the if that detects button6 and run the blinking unconditionally.

I'd suggest that you just increase interval when you detect button6 to start with. That way hopefully, you'll see something working, even if it isn't your full requirement. Incremental development FTW!

ive been trying both options with the use of a variable delta and the other way of putting interval adjustment code into the "if" that detects button 6, but no further forward.

Adding the below code does not work (it flashes at button6 press but no change in speed on next press of button) but is it close to what you were thinking? I'm guessing the && is the reason along with my lack of my knowledge at this moment in time!

No laughing at my (not so) genius coding knowledge! :smiley:

if (results.value == button6 && interval +100)

Post all your code.

For what it is worth, the second expression above is always true, unless interval == -100

My code is by far from perfect but this is my first ever atempt at programming so please go easy (especially with the use of "delays") XD

 #include <IRremote.h>
 #define button1 16724175
 #define button2 16718055
 #define button3 16743045
 #define button4 16716015
 #define button5 16726215
 #define button6 16734885
 #define button7 16728765
 #define button8 16730805
 #define RECV_PIN  13


//Pin setup up the Laugh
int Laugh7 = 10;
int Fan = 15;
int delta = 100;


int Laugh[] = {4,5,6,7,8,9};
//  Laugh OPEN FROM BOTTOM
int pattern1[] = {HIGH,LOW,LOW,LOW,LOW,LOW};
int pattern2[] = {HIGH,HIGH,LOW,LOW,LOW,LOW};
int pattern3[] = {HIGH,HIGH,HIGH,LOW,LOW,LOW};
int pattern4[] = {HIGH,HIGH,HIGH,HIGH,LOW,LOW};
int pattern5[] = {HIGH,HIGH,HIGH,HIGH,HIGH,LOW};
int pattern6[] = {HIGH,HIGH,HIGH,HIGH,HIGH,HIGH};

//  Laugh CLOSE FROM TOP
int pattern7[] = {HIGH,HIGH,HIGH,HIGH,HIGH,LOW};
int pattern8[] = {HIGH,HIGH,HIGH,HIGH,LOW,LOW};
int pattern9[] = {HIGH,HIGH,HIGH,LOW,LOW,LOW};
int pattern10[] = {HIGH,HIGH,LOW,LOW,LOW,LOW};
int pattern11[] = {HIGH,LOW,LOW,LOW,LOW,LOW};
int pattern12[] = {LOW,LOW,LOW,LOW,LOW,LOW};

//  Laugh OPEN CLOSE FROM CENTER
int pattern13[] = {LOW,LOW,LOW,LOW,LOW,LOW};
int pattern14[] = {LOW,LOW,HIGH,HIGH,LOW,LOW};
int pattern15[] = {LOW,HIGH,HIGH,HIGH,HIGH,LOW};
int pattern16[] = {HIGH,HIGH,HIGH,HIGH,HIGH,HIGH};
int pattern17[] = {LOW,HIGH,HIGH,HIGH,HIGH,LOW};
int pattern18[] = {LOW,LOW,HIGH,HIGH,LOW,LOW};
int pattern19[] = {LOW,LOW,LOW,LOW,LOW,LOW}; 

// Variables will change:
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 200;           // interval at which to blink (milliseconds)


int times ;
 IRrecv irrecv(RECV_PIN);
 decode_results results;
 long lReceived = 0 ;

void setup()
{
  Serial.begin(9600);
   irrecv.enableIRIn(); // Start the receiver
  //Set each pin connected to an LED to output mode (pulling high (on) or low (off)
  for(int i = 0; i < 6; i++)
  {       
      pinMode(Laugh[i],OUTPUT); 
      pinMode(Laugh7,OUTPUT); 
      pinMode(Fan,OUTPUT);
      
  }                             
}
  
void loop () 
{
  if (irrecv.decode(&results)) {
    Serial.println(results.value);
    irrecv.resume(); // Receive the next value
  
  
    if (results.value == button1)
{
       
       digitalWrite(4, LOW);
       digitalWrite(5, LOW);
       digitalWrite(6, LOW);
       digitalWrite(7, LOW);
       digitalWrite(8, LOW);
       digitalWrite(9, LOW);
       digitalWrite(10, LOW);
}
       
     else {
       
       digitalWrite(4, HIGH);
       digitalWrite(5, HIGH);
       digitalWrite(6, HIGH);
       digitalWrite(7, HIGH);
       digitalWrite(8, HIGH);
       digitalWrite(9, HIGH);
       digitalWrite(10, HIGH);
}
  }
    
else if  (results.value == button2) 
    
     for (int i=0; i <= 100000; i++){
       digitalWrite(10, LOW);
    
   //  Laugh OPEN CLOSE FROM TOP
  makePattern(Laugh, pattern1, 6);
  makePattern(Laugh, pattern2, 6);
  makePattern(Laugh, pattern3, 6);
  makePattern(Laugh, pattern4, 6);
  makePattern(Laugh, pattern5, 6);
  makePattern(Laugh, pattern6, 6);
  makePattern(Laugh, pattern7, 6);
  makePattern(Laugh, pattern8, 6);
  makePattern(Laugh, pattern9, 6);
  makePattern(Laugh, pattern10, 6);
  makePattern(Laugh, pattern11, 6);
  makePattern(Laugh, pattern12, 6);
  break;
  irrecv.resume(); // Receive the next value
   }
     
else if (results.value == button3)
       for (int i=0; i <= 1; i++){
         digitalWrite(10, LOW);
    
  
  //  Laugh OPEN CLOSE FROM CENTER
  makePattern(Laugh, pattern13, 6);
  makePattern(Laugh, pattern14, 6);
  makePattern(Laugh, pattern15, 6);
  makePattern(Laugh, pattern16, 6);
  makePattern(Laugh, pattern17, 6);
  makePattern(Laugh, pattern18, 6);
  makePattern(Laugh, pattern19, 6);
  break;
  irrecv.resume(); // Receive the next value
       }
     
else if (results.value == button4)
       for (int i=0; i <= 1; i++){
         digitalWrite(10, LOW);
    
  
  //  Laugh OPEN CLOSE FROM BOTTOM
  makePattern2(Laugh, pattern12, 6);
  makePattern2(Laugh, pattern11, 6);
  makePattern2(Laugh, pattern10, 6);
  makePattern2(Laugh, pattern9, 6);
  makePattern2(Laugh, pattern8, 6);
  makePattern2(Laugh, pattern7, 6);
  makePattern2(Laugh, pattern6, 6);
  makePattern2(Laugh, pattern5, 6);
  makePattern2(Laugh, pattern4, 6);
  makePattern2(Laugh, pattern3, 6);
  makePattern2(Laugh, pattern2, 6);
  makePattern2(Laugh, pattern1, 6);
  break;
  
  irrecv.resume(); // Receive the next value
       }
       if (results.value == button5)
      
       
{
              
              unsigned long currentMillis = millis();
  
   if(currentMillis - previousMillis > interval) {
     // save the last time you blinked the LED 
    previousMillis = currentMillis;  
    

    // if the LED is off turn it on and vice-versa:
     if (ledState == LOW)
       ledState = HIGH;
     else
       ledState = LOW;
 
    // set the LED with the ledState of the variable:
     digitalWrite(10, ledState);
     digitalWrite(4, ledState);
     digitalWrite(5, ledState);
     digitalWrite(6, ledState);
     digitalWrite(7, ledState);
     digitalWrite(8, ledState);
     digitalWrite(9, ledState);
   

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


/*
 * makePattern - this function has three parameters:
 *   leds[]-an array of output pins connected to LEDs
 *   pattern[]-an array containing HIGH or LOW to indicate whether an LED is on or off
 *   num-the number of LEDs
 */
void makePattern(int leds[], int pattern[], int num)
{
  int delayTime = 100;
  for(int i = 0; i < num; i++)
  {
    digitalWrite(leds[i], pattern[i]); 
  }
  delay(delayTime);
}
       
void makePattern2(int leds[], int pattern[], int num)
{
  int delayTime = 50;
  for(int i = 0; i < num; i++)
  {
    digitalWrite(leds[i], pattern[i]); 
  }
  delay(delayTime);
}

I thought you were trying to change the speed of a LED blinking?
What's all that other stuff?

The IDE has a useful auto format tool that will help tidy up your code before you post.

A few comments:
Once a pin mode is set, it stays that way. There is no need to keep setting Laugh7 as an output. Ditto Fan.

Storing one bit of information in a variable designed for sixteen bits is a waste of storage. RAM is precious on a micro controller, don't waste it.

The other stuff is code that (if you imagine a mouth) makes strips of LED turn on and off in a seqeuence, like amouth opening and closing or laughing.

I'm happy with the sequences and that and it works with button presses, but now I would like all the strips of LED's to flash on and off at the same time but with ability to increase or decrease the rate on a press of a remote button.

Sorry about the long code post.

****Just seen your edits.... OK thank you, thats very useful to know. I'll sort those bits out now. ****