(SOLVED) Assigning variable to pins (Newbie needs help)

I apologise if this post is in the wrong section and this is my first post (probably many more to come). I am a complete beginner as far as Arduino is concerned and have bought the book ‘Arduino Projects for Dummies’ and working through the book. I have an Arduino Uno R3 and I am currently working on the project ‘The All Seeing Eye’ which basically fires up a series of 10 LED’s in sequence and which change direction when the last LED in the row lights up. I have been playing around with the variables and I am puzzled by this line in the code “int currentLED = 4;” (ignore the inverted commas). According to the book the LED connected to Pin 4 should light up first. But it doesn’t; the LED connected to Pin 8 on the board lights up. 5 lights up LED connected to Pin 9, 6 lights up LED connected Pin 10 and so on. Can anyone please explain what is happening here before I pull the rest of my already sparse hair out!

May I first recommend that you read the “How To Use This Forum” thread at the top of the forum.

I can’t immediately determine what is wrong until I see your code, because if you set pin 4 to HIGH and you have an LED correctly connected to pin 4, it will go on…

But as stated by DrAzzy below, it is most likely that there is an offset because the programmers didnt want to use pins 0 and 1, which are primarily used for serial communication. It would make sense that pin 4 is the first LED, and pins 5,6,7,8,9,10,11,12,13 are the other 9 LEDs.

EDIT: After looking online to download the book, failing, then looking online for the chapter, your welcome by the way, I have come to this page Chapter 4 which does indeed show that the first LED is connected to pin 4, so currentLED = 4; is specifying that the first LED is connected to pin 4

And DrAzzy, you called it, there is, in fact, an array mapping position to pin number,
“byte ledPin = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13};”

Here is the code

// http://123d.circuits.io/circuits/412319-aeduino-001-test-proj/edit
// Chapter 4: The All-Seeing Eye
// Sequentially lights up a series of LEDs
// A variable to set a delay time between each LED
int delayTime = 40;

// A variable to store which LED we are currently working on
int currentLED = 4;

// A variable to store the direction of travel
int dir = 1;

// A variable to store the last time we changed something
long timeChanged = 0;

// An array to hold the value for each LED pin
byte ledPin[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13};

void setup()
{
	// Set all pins for OUTPUT
	for (int i=0; i<10; i++) {
		pinMode (ledPin[i], OUTPUT) ;
		}

// Record the time once the setup has completed
timeChanged = millis ( ) ;
}

void loop () {
	// Chect whether it has been long enough
	if ((millis() - timeChanged) > delayTime)
	{
	
	//turn off all of the LEDS
	for (int i=0; i<10; i++) {
	digitalWrite(ledPin[i], LOW) ;
	}

	// Light the current LED
	digitalWrite(ledPin[currentLED], HIGH);

	// Increase the direction value (up or down)
	currentLED = currentLED + dir;

	// If we are at the end of a row, change direction
	if (currentLED == 9) {
	dir = -1;
	}

	if (currentLED == 0) {
	dir = 1;
	}

	// store the current time as the time we last change LEDs
	timeChanged = millis();

	}

}

Well, since we don't all have copies of all of the hundreds of learn-arduino books (particularly as the people whose advice you want probably haven't looked at an intro book in years), and you haven't posted the code, I'm not sure how you expect us to be able to help - post the code if you want us to explain it. My first guess would be that that's the position of in the row of 10 LEDs that they're starting with, and they have an array somewhere to map the position to the pin number - though even suggesting something like this without seeing the code is rather premature.

We don't like people posting snippets of code and asking for help - because you inevitably waste time making assumptions about what the rest of the code is, when it's not like that - and you haven't even posted a snippet, just a single line.

int currentLED = 4;

the LED connected to Pin 8 on the board lights up.

Is there an array of LED pin numbers and if so, is there an 8 in the fifth position in the array ? Array indexes start at 0 hence 4 being the fifth position.

Looking forward to seeing the code.

My apologies for not reading the ‘how to post thread’. I believe that UKHeliBob has answered my query; there is an array in the code and with the array index starting at 0, I now understand why LED on Pin 8 lights up. I have a lot to learn! Thank you all for your advice and assistance.

Here is the code:

/* Arduino Projects for Dummies
 * by Brock Craft 
 *
 * Chapter 4: The All-Seeing Eye
 * Sequentially lights up a series of LEDs
 *
 * v0.3 02.02.2015
 * Changed delayTime variable so that is is consistent with the 
 * text of the book. (Used to be timeDelay.)
 * v0.2 03.07.2013
 * Fixed error: timeChanged = millis(); not within if loop brackets
*/

// A variable to set a delay time between each LED
int delayTime = 40; 

// A variable to store which LED we are currently working on
int currentLED = 4;

// A variable to store the direction of travel of LEDs
int dir = 1;

// A variable to store the last time we changed something
unsigned long timeChanged = 0;

// Create an array to hold the value for each LED pin
byte ledPin[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13};

void setup() {
  // Set all pins for OUTPUT
  for (int x=0; x<10; x++) {
    pinMode(ledPin[x], OUTPUT); 
  }

 // Set up the 
  timeChanged = millis();
}

void loop() {
  // Check whether it has been long enough
  if ((millis() - timeChanged) > delayTime) {

    // Turn off all of the LEDs
    for (int x=0; x<10; x++) {
      digitalWrite(ledPin[x], LOW);
    }

    // Turn on the current LED
    digitalWrite(ledPin[currentLED], HIGH);

    // Increment by the direction value
    currentLED += dir;

    // If we are at the end of a row, change direction
    if (currentLED == 9) {
      dir = -1;
    }
    if (currentLED == 0) {
      dir = 1;
    }
  

  // Store the current time as the time we last changed LEDs
  timeChanged = millis();
  }
}