0

syntax question
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

syntax question

by zacnotes on Thu Apr 09, 2009 1:04 am

i am learning the arduino language, and after obtaining a solid grasp here at ladyada, i have moved on to the different examples at the arduino site. The specific program i am looking at is the piezzo lesson, and my question is about the "void" statements at the beginning. there are 2 of them, and they are not followed by a "loop" or "setup" and actually come before the "setup" procedure. Can someone please explain this to me, as it is grammar i have not yet encountered?
thanks!
The best toys are ones you can fix, even if they aren't broken.
zacnotes
 
Posts: 6
Joined: Wed Feb 18, 2009 12:42 pm
Location: Arizona

Re: syntax question

by westfw on Thu Apr 09, 2009 2:49 am

"void" here means that the subroutine ("function") being defined does NOT return a value.
This would be in contrast to a function like "sin(x)" which returns a floating point value just like a proper mathematical function.

westfw
 
Posts: 1603
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: syntax question

by zacnotes on Wed Apr 15, 2009 11:41 pm

does the setup portion have to return a value? in this example, the only thing in the void setup is the pinMode declaration, and i don't think that has a returned value, right?
The best toys are ones you can fix, even if they aren't broken.
zacnotes
 
Posts: 6
Joined: Wed Feb 18, 2009 12:42 pm
Location: Arizona

Re: syntax question

by mtbf0 on Thu Apr 16, 2009 5:24 am

zacnotes wrote:does the setup portion have to return a value?


no. it can't return a value. it's declared void.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Re: syntax question

by zacnotes on Thu Apr 16, 2009 11:24 pm

So, referencing my original post, why have 2 separate void routines, and not include them in the setup routine?
The best toys are ones you can fix, even if they aren't broken.
zacnotes
 
Posts: 6
Joined: Wed Feb 18, 2009 12:42 pm
Location: Arizona

Re: syntax question

by unwiredben on Fri Apr 17, 2009 1:23 am

The setup() routine is run once by the Arduino runtime when the board first boots. The loop() routine is run over and over. There's nothing special here -- setup could have a loop in it and never return control, and that would be fine. It's just a nice, standard way to structure code for an embedded system, and it makes it clear that the device never exits, it just runs your code over-and-over until powered off or reset.

If you look in your arduino-0015\hardware\cores\arduino folder at main.cxx, you'll see the code that calls setup() and loop(). There's no checking of any return values, as expected since those functions don't return any value.

unwiredben
 
Posts: 75
Joined: Fri Dec 19, 2008 2:02 pm
Location: Brooklyn, NY

Please be positive and constructive with your questions and comments.