Go Down

Topic: What does this code mean? (Read 936 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)
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0


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