Go Down

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

AlphaBeta

I would say that the init handles things that you normally have to worry about on other platforms, but the Arduino does some things behind the scenes.
The init is an important part of this 'behind the scenes' and you should be thankful it's there. You normally do not need to know what it does.

The only thing to know, is that there are some things you can not do before the init has been called, so when the time comes fro writing libraries/classes then you need to refrain from doing certain things in the constructors as they might run before init has.

Zoandar

Thanks. It seems like I ran across it in the first book I read, but I would probably have to search the book to find where I saw it.
Zoandar
  ---v/\/\/\v---

AWOL

#27
Mar 09, 2011, 10:34 pm Last Edit: Mar 09, 2011, 10:54 pm by AWOL Reason: 1
Quote
It seems like I ran across it in the first book I read

It is very difficult, but you have to separate the language from the environment.
The language permits and constructs such devices as
Code: [Select]
cout << "Hello World!" << endl;, but the environment actually implements them, and on the Arduino, "cout" is not part of the environment.

If you look at the link I posted earlier, you'll see it is quite possible to write
Code: [Select]
Serial << "Hello World!" << endl;, which may seem the same, though some of the wider implications of "cout" are absent.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Zoandar


Thanks. It seems like I ran across it in the first book I read, but I would probably have to search the book to find where I saw it.


Actually, I just looked back through that book, and it is not in there anywhere. I think the confusion in my memory was that when I first saw an "int" statement, I mistook the command to mean "initialize" instead of "integer". Sometimes it is hard to drop those early misconceptions as more is learned. :)

I guess each person has their preferences in how they like to program, too. In Mazzimo's book, when he wanted to set up an LED on pin 13 he used the command

Code: [Select]
#define LED 13

and then to light it he used

Code: [Select]
digitalWrite(13, HIGH)

But in Maik's Quick Start Guide book, he uses the command

Code: [Select]

const unsigned int LED_PIN = 13;


This had me scratching my head until I figured out what he was going to do with it, using LED_PIN as a variable name. So to light it he used
Code: [Select]

digitalWrite(LED_PIN, High);


As they saying goes - "same difference". :)


Zoandar
  ---v/\/\/\v---

AWOL

#29
Mar 09, 2011, 11:27 pm Last Edit: Mar 09, 2011, 11:30 pm by AWOL Reason: 1
Quote
This had me scratching my head until I figured out what he was going to do with it, using LED_PIN as a variable name

No, really most definitely NOT a variable name in either case.

If you have any doubts, try
Code: [Select]
LED_PIN = 12; or
Code: [Select]
LED = 12; somewhere in your sketch
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up