user69677: #include <Adafruit_NeoPixel.h>
const int PIN = 4;
const int NUMPIXELS = 10;
const int BUTTONPIN = 6;
int buttonState = 0;
int PINState = 0;
int level = 1;
int dt = 100;
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pixels.begin();
  pinMode(BUTTONPIN, INPUT);
  Serial.begin(9600);
}

void loop(void) {
Serial.println(buttonState);
  buttonState = digitalRead(BUTTONPIN);
  if (digitalRead(BUTTONPIN) == HIGH) {
    if (buttonState == 0) {
      buttonState = 1;
    } else {
      buttonState = 0;
    }
  }

  if (buttonState == 1) {
    opdracht(level);
  }
  else {
    if (level >= 10) {
      level++;
    } else {
      level = 1;
    }
    pixels.clear();
  }
}

//level 1
//void opdracht1() {
//  pixels.setPixelColor(0, pixels.Color(150, 0, 0));
//  pixels.setPixelColor(5, pixels.Color(0, 0, 150));
//  pixels.show();
//}

void opdracht(int x) {
  if (x == 1) { //level 1
    pixels.setPixelColor(0, pixels.Color(150, 0, 0));
    pixels.setPixelColor(5, pixels.Color(0, 0, 150));
    pixels.show();
  }

  if (x == 2) { //level 2
pixels.setPixelColor(8, pixels.Color(150, 0, 0));
pixels.setPixelColor(6, pixels.Color(150, 0, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 150));
pixels.show();
  }


user7508: You forgot to ask a question. So I will assume the intended question is
“Why does this code always show level 1?” and I will try to answer that.
The variable level is defined here:
int level = 1;

Its initial value is 1. Then it is updated here:
if (level >= 10) {
  level++;
} else {
  level = 1;
}

The first time this section of code runs, level has its initial value,
namely 1. The condition in the if evaluates to false, then the
statement
level = 1;

is executed, which assigns the value 1 to level (which has no effect,
as that was already its value anyway).
The next time that section of code runs, level has still the vale 1,
and the effect is the same as the previous time.

69677: <pre class="lang-cpp prettyprint-override"><code>#include &lt;Adafruit_NeoPixel.h&gt;
const int PIN = 4;
const int NUMPIXELS = 10;
const int BUTTONPIN = 6;
int buttonState = 0;
int PINState = 0;
int level = 1;
int dt = 100;
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pixels.begin();
  pinMode(BUTTONPIN, INPUT);
  Serial.begin(9600);
}

void loop(void) {
Serial.println(buttonState);
  buttonState = digitalRead(BUTTONPIN);
  if (digitalRead(BUTTONPIN) == HIGH) {
    if (buttonState == 0) {
      buttonState = 1;
    } else {
      buttonState = 0;
    }
  }

  if (buttonState == 1) {
    opdracht(level);
  }
  else {
    if (level &gt;= 10) {
      level++;
    } else {
      level = 1;
    }
    pixels.clear();
  }
}

//level 1
//void opdracht1() {
//  pixels.setPixelColor(0, pixels.Color(150, 0, 0));
//  pixels.setPixelColor(5, pixels.Color(0, 0, 150));
//  pixels.show();
//}

void opdracht(int x) {
  if (x == 1) { //level 1
    pixels.setPixelColor(0, pixels.Color(150, 0, 0));
    pixels.setPixelColor(5, pixels.Color(0, 0, 150));
    pixels.show();
  }

  if (x == 2) { //level 2
pixels.setPixelColor(8, pixels.Color(150, 0, 0));
pixels.setPixelColor(6, pixels.Color(150, 0, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 150));
pixels.show();
  }
</code></pre>
 7508: <p>You forgot to ask a question. So I will assume the intended question is
“Why does this code always show level 1?” and I will try to answer that.</p>
<p>The variable <code>level</code> is defined here:</p>
<pre class="lang-cpp prettyprint-override"><code>int level = 1;
</code></pre>
<p>Its initial value is 1. Then it is updated here:</p>
<pre class="lang-cpp prettyprint-override"><code>if (level &gt;= 10) {
  level++;
} else {
  level = 1;
}
</code></pre>
<p>The first time this section of code runs, <code>level</code> has its initial value,
namely 1. The condition in the <code>if</code> evaluates to false, then the
statement</p>
<pre class="lang-cpp prettyprint-override"><code>level = 1;
</code></pre>
<p>is executed, which assigns the value 1 to <code>level</code> (which has no effect,
as that was already its value anyway).</p>
<p>The next time that section of code runs, <code>level</code> has still the vale 1,
and the effect is the same as the previous time.</p>
