Pages: [1]   Go Down
Author Topic: What does this code mean?  (Read 489 times)
0 Members and 1 Guest are viewing this topic.
India
Offline Offline
Newbie
*
Karma: 0
Posts: 21
Induino X is awesome!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 620
Posts: 33991
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Johannesburg. UTC+2
Offline Offline
Faraday Member
**
Karma: 91
Posts: 4258
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley-cool
Logged

Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 216
Posts: 13673
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Rob Tillaart

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

Beijing
Offline Offline
Full Member
***
Karma: 3
Posts: 193
Skype name habib.derbyshire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

When I used it, I forgot that it was being printed in hex and that caused me a lot of trouble.
Logged

What is man's best friend? The breadboard!

Pages: [1]   Go Up
Jump to: