Arduino: 1.0.6 (Mac OS X), Board: 'Arduino Uno' IR2:10: error. What is not right is the library folder name. Iremote!= IRremote. Please do not. First I need to remove my IR Robot library because it interferes with the IRremote library. On my Mac, I have gone into the Arduino/library folder,.
![]() ![]()
This isn't meant to be a putdown at all so please don't take it as one- but if you're just asking for the code then why not just use the IRremote library?If you actually do want to do it yourself then I can give you some pointers and walk you through the way that I've done it.has some excellent information on interrupts and how to use them.To read what's coming off the IR receiver you can have pin change interrupt that it triggered by the receiver. You also use a timer to get the pulse length values- choose one that won't clash with any other libraries you're using.Each time the interrupt fires you can record the value of the timer, and whether the pin is going high or low.
![]()
You can also keep a count of the amount of pulses that have come in if you're looking for that.Then you reset the timer and exit the ISR. This were most of the problem lies. First off, since this function is only ever called from the ISR there's no need to have it separate to the ISR- just have it all as part of the ISR.Secondly, it is try to use delay inside the ISR, which just doesn't work. You'd also only be reading every other state, since the whole ISR checks for the state to change again before exiting. This might be what you want- you might only care about the low pulses and not about the high pulses for example- but just be aware of that.This is more like what I'd do. This is just pseudo code but it isn't too complicated.
Code:volatile unsigned long pulseLengthvolatile byte iYou can make the pulseLength array as big as you'd like to handle as many pulses as you need to.You could also optimise it a fair bit- if you know that the pulse length is going to be less than 65,535 milliseconds then you could change pulseLength from an unsigned long to an unsigned int. Or if it is always going to be less than 255 milliseconds then you could change it to a byte.You could also have a separate array for high pulses and low pulses, and load length of the pulse into the correct variable by checking if the pin is high or low at the start of the ISR.
![]() Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |