Understanding Arduino C commands.

Hi,

I am a newbie, learning C so that I can create sketches. Can anyone recommend a book (or other) that explains how Arduino sketches (in C) sets up the Arduino board.

For example, I have read the following basic command + comment:

int ledPin = 13; //which apparently sets up Arduino pin 13 to be connected to LED.(Further commands sets it as OUTPUT and then HIGH/LOW).

BUT....my limited C logic tells me that this command sets up a variable called ledPin with an initial value of 13???

Can anyone please point me in the direction of a good book that explains the logic behind skethes.

Thanks

Iain

For example, I have read the following basic command + comment:

That isn't a command. It's a variable declaration and assignment.

All it is doing is allocating memory and storing a value in that memory location. It names that memory location for easy access later.

It does not bind pin 13 to anything.

Your understanding of C is correct. Your comment is wrong.

If you want to set the pin as output, you have to use the pinMode function.

pinMode(ledPin, OUTPUT);

To set the pin high or low, you use the digitalWrite function:

digitalWrite(ledPin, HIGH);

In the Reference part of that website there's documentation for all the Arduino functions. It's good to get familiar with it.

Your understanding of C is fine. The confusion is brought about by the fact that the UNO happens to have an LED on it that is arbitrarily connected to pin thirteen. There's no magic behind the scenes and if you used any other pin, you'd have to provide your own LED to light it.

It's a convenience to allow you write your first blink program without the complexity of having to connect other hardware.

iain777:
my limited C logic tells me that this command sets up a variable called ledPin with an initial value of 13???

You are correct - that is all that statement does.