Go Down

Topic: What does this code mean? (Read 567 times) previous topic - next topic


void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value

I would like to know the use of each line and what does that &results within brackets mean?


Without knowing the rest of the code it is hard to tell but:-
irrecv.decode is a function to which you pass the address, the & bit, of a variable called results.


Based on the name, I would guess that irrecv.decode() receives / decodes a message and puts that result in a struct called results. One of the elements in results is value, which is being sent serially.


It's from Ken Shirriff's IRrecvDemo sketch. When I worked with that sketch, I must say I didn't even bother to try and understand it, I just used it  8)
"Could you do the egg bacon spam and sausage without the spam then? "

No PMs for help please.
DO NOT power servos from Arduino 5V: give them their own power and connect the grounds.


if you want to learn the details, you should "dissect" the library that you included in the code and follow it line by line.
Where did you got this code? there is probably some explanation/documentation in its neighbourhood.

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


When I used it, I forgot that it was being printed in hex and that caused me a lot of trouble.
What is man's best friend? The breadboard!

Go Up