Go Down

Topic: Understanding this line " ? HIGH : LOW; " (Read 8582 times) previous topic - next topic

PaulS

Quote
Are you saying that the code shown in Arduino Reference will not run if used in a C++ platform?

Most of the functions on that page, including those I listed, are specific to the Arduino, and will result in undefined references on any other C++ platform.

Quote
So whatever bounce.cpp is, it is using bounce.h as an included library. (Are there "libraries" with 'sub-libraries'? )

The bounce.cpp file is the source file. It is where the methods of the class are implemented.
The bounce.h file is the header file. It is where the class, and it's methods and fields, are defined.
The implementation file, and whatever sketches need to use that class, need to include the header file.
Together, the source and header file make up what the Arduino platform refers to as a library.

Zoandar

#76
Mar 12, 2011, 03:24 am Last Edit: Mar 12, 2011, 03:32 am by Zoandar Reason: 1
Thanks!

So, what is the difference between something being a method or just a function? Is it a method BECAUSE it is a function that is part of a class? Or are there other reasons? Would a C++ guide perhaps spell this part out?

I found this on a C++ forum. The first part of the dialog makes sense, but then they sort of got convoluted toward the end of the thread. :)

http://www.cplusplus.com/forum/beginner/20406/
Zoandar
  ---v/\/\/\v---

Zoandar


Quote
Are you saying that the code shown in Arduino Reference will not run if used in a C++ platform?

Most of the functions on that page, including those I listed, are specific to the Arduino, and will result in undefined references on any other C++ platform.

Quote
So whatever bounce.cpp is, it is using bounce.h as an included library. (Are there "libraries" with 'sub-libraries'? )

The bounce.cpp file is the source file. It is where the methods of the class are implemented.
The bounce.h file is the header file. It is where the class, and it's methods and fields, are defined.
The implementation file, and whatever sketches need to use that class, need to include the header file.
Together, the source and header file make up what the Arduino platform refers to as a library.


Thanks! This is starting to come together for me.
Zoandar
  ---v/\/\/\v---

Nick Gammon


So, what is the difference between something being a method or just a function? Is it a method BECAUSE it is a function that is part of a class?


Hmm, I may have misused the word "method". (C++ was not my first language).

I intended it in the sense of "member function", that is a function (so yes it is a function) but as a member of a class. Originally when I learned object-oriented programming such things were called methods.

Basically a non-static member function has no meaning unless it is called with reference to an instance of a class. When so-called, that particular instance is known as "this".

This is getting a bit deep, let's not get bogged down in words here. Let's call them functions, bearing in mind that functions defined as part of a class "refer" (if I can use the word) to a particular instance of that class. So for example:

Code: [Select]
Bounce mybutton (8, 100);
int x = mybutton.read (); 


So "read" is a member function of Bounce, and in this particular case we are reading the value of "mybutton", which is an instance of that class (the Bounce class).
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Zoandar

Sounds great to me! I can't get too deeply into this or I probably won't be able to retain enough of it to be useful to me. Hands-on learning works best for me, so what I can see by doing these Arduino projects will stick the best in my mind. It seems from what you all have told me that Arduino is the micro-tip of an enormous iceberg encompassing the C language and its variants. And from what I have seen on the C++ sites where I did find helpful information today, as you suggested, this language can get VERY deep in short order.

As long as I can have someone toss me a line now and then to sort out things I encounter without explanation I should be OK. So far you all have thankfully been doing just that. I'm preparing to move on in the book, now that I have had my questions answered.

Thanks!!   :D
Zoandar
  ---v/\/\/\v---

Zoandar

I just happened across an additional "Reference" for Arduino aside from the one reachable in the Help menu. It seems to cover more things. For example I can do a search there for "class" and actually find the definition of a class :) I just happened to stumble across it when I was reading about "int" again in the Arduino Reference. At the bottom of that page, there are some "See Also" links. I had clicked on the one for Variable Declaration, and it took me to this page:

file:///C:/arduino-0022/reference/VariableDeclaration.html

There is a search field there, and when used it yields Google hits for the search term entered, but all the Google returns seem to be focused on pages common to arduino.cc/x where "x" is various subtopics. So I can add this to my "list" of places from which I can find information about Arduino coding. :)
Zoandar
  ---v/\/\/\v---

chrisribe


Quote

Unstick yourself from the notion that everything needs to be documented on the Reference page.


I agree 100% that the entire C++ language should not be documented on the reference page.  What should be documented on the reference page is that fact that any valid C++ code* is valid Arduino code.

I am a professional programmer who has been using Arduino casually for about 6 months now, and it wasn't until a few weeks ago that I figured out this very important point! 

Here is the only relevant line from the Arduino "Getting Started", "Introduction", and "Reference" pages:
Quote
The Arduino programming language is an implementation of Wiring, a similar physical computing platform, which is based on the Processing multimedia programming environment.


Unless a new user stumbles across and reads the "Arduino Build Process" page (http://arduino.cc/en/Hacking/BuildProcess), a document which would quickly overwhelm most beginners, they would have no idea that Arduino was any more related to C++ than JavaScript is to Smalltalk!

Throughout the documentation, Arduino is presented as a "language."  I took that to mean it was a distinct language and that the provided reference was a complete one.  I was taken by surprise when I discovered what Arduino really is.  It turns out the "Arduino programming language" is nothing but C++, a simple pre-preprocessor, and some hardware interface libraries.  And it is genius! At every level of the Arduino ecosystem, the developers have added just enough of a veneer of simplicity to lure in beginners without reducing the power of the underlying tools.  They aren't doing beginners any favors by obscuring the Arduino programming language's C++ roots, though.   

*valid avr-g++ code


     

u0421793

Simply refer to the book I initially obtained when I thought the arduino was a good thing to try "Programming Interactivity, a designer's guide to Processing, Arduino and open frameworks" -- it clearly draws a distinction by referring to the language as either Processing or Arduino (depending where in the book you are). The first half of the book teaches it as "Processing". My book suffered a sudden existence failure quite some time ago, but the point is, it was always referred to as a language called either Processing or Arduino in that book.

hobbified


So, what is the difference between something being a method or just a function? Is it a method BECAUSE it is a function that is part of a class? Or are there other reasons? Would a C++ guide perhaps spell this part out?


In the general world of programming (not C++ specific), yes, a "method" is a function that is part of a class, and we can more specifically speak of "instance methods" (methods that are called on objects, i.e. instances of some class) and "class methods" (methods that are called on the class itself, without reference to any specific object). C++ also calls methods "member functions" (or to be painfully accurate "virtual member functions") and class methods "static member functions" for reasons that are historical and painfully silly. Java and C# also abuse the word "static" in this way. You should know the terms that your language uses, and use them when you need to be specific about things that are specific to your language, but in general you should be comfortable with the general terms. :)

Zoandar

Thanks for the clarifications, hobbified. I agree that knowing the right terminology when trying to discuss something sure makes things easier to understand. But, just like reading a dictionary won't teach you the English Language, encountering term definitions, even when they are easily made available, doesn't lend to understanding when and where to use each one. That comes through experience.

Luckily for me, 75 pages into this Arduino - A Quick-Start Guide, the author has finally revealed the 'mother-lode' of gaining an understanding to all these terms, what they are used for, and where they "come from" when they are not readily seen in the tiny "Reference" page of Arduino. He is now talking about libraries, header files, source files, and the great many of them which get referenced "behind the scenes" as previous posts in this thread have pointed out. On this page of the book he suggests looking into the ....cores/arduino folder (the path appears to have changed since he wrote the book so I did not spell it out as he did, because it would be wrong in version 0022's file structure) at all the header and other files which reside therein, and which provide all the constants such as HIGH, LOW, OUTPUT, etc. Currently there are 24 files in that folder, of file extensions ".h" (header files), ".cpp" (source files) and ".c" files which he has yet to mention, and Google can't seem to provide a good description for. But I know they contain code just like header and source files do.

So it is finally all coming together. Admittedly, I am not an author, and I suppose it is difficult when writing such a book to try to decide when to reveal certain types of information so as not to scare away those encountering the book's topic for the first time. I might have done it a bit differently, were it up to me. But I guess we all have our own thoughts on how to teach.
Zoandar
  ---v/\/\/\v---

PaulS

Quote
But I guess we all have our own thoughts on how to teach.

It's important to keep in mind, too, that not everyone learns the same way. Some people learn be reading. Some learn be seeing, Some learn by doing.

In a classroom setting, you could raise your hand and ask questions about what you don't understand. Often, the answer will be "We'll get to that in a few minutes". With a book, that interactivity is missing. So, the context for the book is important. If the book is a text book, the implication is that there will be an instructor to go with it, and some degree of interactivity.

If it's not a text book, then, possibly the editing and proofreading of the book needed to be done by a wider audience.

Beginner books are the hardest to write, since they may be read by people with a wide variety of backgrounds. New to Arduino, but been programming for years. New to Arduino and don't know which end of a soldering iron to hold (you learn that pretty quick). Each group is looking for something different from the book.

If there is a mechanism to provide feedback to the author, take advantage of it. Perhaps a revision or update is planned, and feedback would be useful.

Zoandar

Well said! I'll see if there is a way to reach the author, but in line with what we each said above he may not agree with my suggestions. I have found it quite true that not everyone learns the same way. I may be the exception to a larger group of people.

Later in the book he leaves it up to the reader to figure out where the additional code snippets he displays need to go while building a library file. So I had to 'assume'. I don't ever like doing that when trying to learn something new which has this amount of detail and precision. It can lead to problems that simply would not happen if he just added a sentence or two telling the reader exactly where each segment should go as he proceeds.

Thanks!
Zoandar
  ---v/\/\/\v---

Go Up