Controlling a button I'm going to write a sketch that would light up the first LED (D1) of the training shield at the beginning, then move the LED light to the left or to the right whenever you press the S1 or S2 buttons, respectively. When the LED is already at the first (D1) or the last (D8), it should no longer move when going further to the left or right, respectively.

Looks exactly like this: https://www.youtube.com/watch?v=_KQQTdDMgOU

Here's what I made so far:

int x = 0;

void setup() {
  for(int i=11; i &lt;= 18; i++) {
    pinMode(i, OUTPUT);
  }
}

void loop() {
  x = digitalRead(pushButtonPin);
  if (pushButtonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}
What you made so far is only turn on and off LED according to button state. I believe there's more efficient code out there, but you can try:

int x = 11;

 void setup() {
 for(int i=11; i &lt;= 18; i++) pinMode(i, OUTPUT); //assuming the led is on pin 11-18
 }

 void turnLED(int num)
 {
     for(int i=11; i &lt;= 18; i++) 
         if (num==i) digitalWrite(i,HIGH); else
                     digitalWrite(i,LOW);
 }

 void loop() {

    if (digitalRead(buttonRight)) 
    {
        x++;
        if (x&gt;18) x=18;
    }
    else if (digitalRead(buttonLeft))
    {
        x--;
        if (x&lt;11) x=11;
    }
    turnLED(x); //turn LED on according to value of 'x'
    delay(500); 
}