Debouncing IR

So i have a nice little IR remote setup; its pretty useless but fun. I do have a slight problem though. My remote seems to like to send many copies of the same code(like pressing the button many times) so you end up having to barely push the button for it to register only one button press. Is there a way to debounce it or decrease the IR sampling freqency without using delay()?

you could store the last command seen as well as the last time it was seen (using millis() ) and ignore that command if it hasn't been long enough (say, 500 ms)e

This is the nature of most IR remote controls, they auto repeat the same code for as long as you hold the key down, and it's very difficult to make it send just one character no matter how quick a trigger finger you have. :wink:

You can deal with this behaviour by applying a little logic to your receiver software function. Instead of accepting every character you receive, just check to see if it's different then the last character you received. If it's the same character just ignore it in your code, if it's a different character then treat it as a valid new character. That make sense?

Lefty

Thanks guys. Ironically Lefty, the key that I want to be able to press twice in a row is the one that's giving me trouble. How would using millis() to wait x seconds after a code is received to receve the next code look like I was thinking

when code received
x = millis

after doing something

y = millis()

if y-x >= 500

receive next code

Yep, that is the correct way to use millis (heed the y-x, don't turn those around! y-x will be roll-over safe, while x-y isn't).
I'd implement it like this:

if received command is different from previous, save it and save the millis timestamp.
else if the previously saved millis is more than 500 milliseconds older than current millis, save the new millis.
else don't do the command logic.

Obviously you can tweak the order of checks, I'd probably use a return in the final else so I can have the command code after the checks, without having to worry about the results.
Also, you could put the command handling stuff in its own function and call that from the respective if blocks.