0

I have programmed an IR remote control along with an LED and an 8bit 7segment on an Arduino Uno. the segment displays the number I press via the remote, and the LED turns on and off here's my code:

case 16738455:
  Serial.println(0);
  if (oldvalue == results.value){
    on(num0);
    delay(1000);
    on(num00);
    delay(1000);
    oldvalue = results.value;
  }

oldvalue stores the last value pressed, which is the DEC value of the buttons, num0 displays the number zero, and num00 turns all the segments off. I want the 7segment to blink again when I press the same button again. Can anyone help me with this? Thanks

2

A simple solution would be to not worry about blinking as a piece of code, ie. remove those delays (I hate blocking code) and instead, if you are currently receiving a signal from the remote, do not display any number (or display your num00). Once the value is received and processed, then display that number.

This way, whilst ever the remote button is down, the display will blank out, and the number will appear as soon as the number is released. If it's the same number, then you will see the number, see a blank display, and then see the same number again. Obviously, if it's a different number, the new number would be displayed.

Since most people would only press the remote button for 100-1500ms, it should give you a nice delay anyway.

Finally, you may encounter some flashing if you process the data so quickly and the remote auto repeats. This could be handy if that number is processed multiple times by the receiving unit. The flashing would indicate that that is the case. If that is undesired, implement a simple state machine.

edit: your pastebin code came up whilst I was writing this answer. Having a quick look at your code, I would suggest that in the section:

if (irrecv.decode(&results)) {
  //receiving data? display nothing
  on(num00);
  digitalWrite(ledPin, HIGH);
  Serial.println(results.value, DEC);
  irrecv.resume();
  delay(100);
  int oldvalue = results.value;
  switch(results.value){
    case 16738455:
      Serial.println(0);
      num2display=0;      // make sure to declare this var somewhere
      //if (oldvalue == results.value){
      //  on(num0);
      //  delay(1000); 
      //  on(num00);
      //  delay(1000); 
      //} else {   // I think you missed an else here
      //  oldvalue = results.value;  
      //}
      //on(num0); 
      //delay(1000); // you don't want such large blocking delays
      irrecv.resume();
      break;
    case 16724175:
      Serial.println(1);
      num2display=1;       // add this for each section
      irrecv.resume();
      break;
      . . .
  }
}
else{
  digitalWrite(ledPin, LOW);
  on(num2display);
}

you only set the variable to be displayed, but display num00. Then in the else, you can display that number

  • Responding to a button being released is a little tricky with IR remotes. Unlike a physical button, you don't get a steady signal while the remote button is held. Rather, you get a repeating signal, which could end up looking like lots of presses in quick succession. – Peter Bloomfield Mar 28 '14 at 11:51
  • 1
    @PeterR.Bloomfield I did think of that after the fact (or towards the end of the answer), but that could be easily avoided: you would know the pause between transmissions, set a timeStart flag, and don't display before timeStart+timeLag. Resetting this at the beginning of each new repeated burst would ensure it only appears at the end of the transmission. – Madivad Mar 28 '14 at 12:01
  • Thank you for your help Madivad With all respect but I don't think you understood the code well Here's the youtube link to it's video and what it does: link When I press a button, the 7segment displays that number, but what I want is, when I press the same button twice, the 7segment should blink in the second time, all the segments turn off and on again – Bayar AbdulJabbar Mar 28 '14 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.