user8242: I've created a function whereby an int ('cleanCount') automatically goes up or down (0-1000) based on the situation. The value changes every few milliseconds. 
Based on the value, I would like to turn on or off LEDs. Let's say for every increment of '100' another LED goes on. So if the value is 359 there are 3 leds on, if It would been 899 there would've been 8 LEDs on. 
I could simply write
if (cleanCount <= 100) { // turn on NO LEDs
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    ...
}

...

else if (cleanCount <= 500) { // turn on 4 LEDs
    ...
    digitalwrite(led3, HIGH);
    digitalwrite(led4, HIGH);
    digitalwrite(led5, LOW);
    digitalwrite(led6, LOW);
    ...
}

but that would be a big pile of code which could be way more efficient. Perhaps.. my code isn't even correct.
So how could this be more efficient or perhaps actually working?

The whole code, here below.
int cleanCount = 1000;
int softpotPin = A0; //analog pin 0



void setup () {
    Serial.begin(9600);
    digitalWrite(softpotPin, HIGH); //enable pullup resistor    
}


void loop() {
    int softpotReading = analogRead(softpotPin);
    if (softpotReading < 980) { // IF AANGERAAKT
        digitalWrite(werktIeLED, HIGH); 
        ++cleanCount;
        Serial.println(cleanCount);
        delay(16); // 5x zo snel als leeglopen
    }
    else if (softpotReading > 980) { // IF NIET AANGERAAKT
        digitalWrite(werktIeLED, LOW); 
        --cleanCount;
        Serial.println(cleanCount);
        delay(64); // 1000 / 60 seconden
    }
    else {      // Als er een fout optreed..
        Serial.println("Fout!");
        digitalWrite(werktIeLED, HIGH);    
        delay(250);               
        digitalWrite(werktIeLED, LOW);    
        delay(250);               
    }


}


user2973: Here is a suggestion with the led pins in an array that you loop over.
I suggest making the array global, so put it outside any functions (usually at the top):
byte led_pins[] = {pin1, pin2, pin3, pin4, pin5, pin6, pin7, pin8};

Then put this in your loop (assumes that you have a int called cleanCount that is in scope:
const int increment = 100;

for (int i = 0; i < sizeof(led_pins) / sizeof(led_pins[0]); i++) {
  boolean onOrOff = cleanCount > (i+1) * increment;
  digitalWrite(led_pins[i], onOrOff);
}


user2944: You can use the barGraph example from the Arduino code examples. This gives a bar-type graph and not point. I will give rough explination why it will work and the need not to re-invent the wheel.
    int sensorReading = analogRead(analogPin);
  // map the result to a range from 0 to the number of LEDs:
  int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);

  // loop over the LED array:
  for (int thisLed = 0; thisLed < ledCount; thisLed++) {
    // if the array element's index is less than ledLevel,
    // turn the pin for this element on:
    if (thisLed < ledLevel) {
      digitalWrite(ledPins[thisLed], HIGH);
    } 
    // turn off all pins higher than the ledLevel:
    else {
      digitalWrite(ledPins[thisLed], LOW); 
    }
  }

int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);
This will give you the point in the array, 0-10, for 0-1000, if you replace 1023 with 1000
Simplified map() function:
int point = sensorReading*10/1000 this gives you a range of 0-10, the int keeps it from having decimal points.
As you can see from the for loop it turns on all the LEDs that are in the array to the end and then turns off those not needed.

8242: <p>I've created a function whereby an int ('cleanCount') automatically goes up or down (0-1000) based on the situation. The value changes every few milliseconds. </p>

<p>Based on the value, I would like to turn on or off LEDs. Let's say for every increment of '100' another LED goes on. So if the value is 359 there are 3 leds on, if It would been 899 there would've been 8 LEDs on. </p>

<p>I could simply write</p>

<pre><code>if (cleanCount &lt;= 100) { // turn on NO LEDs
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    ...
}

...

else if (cleanCount &lt;= 500) { // turn on 4 LEDs
    ...
    digitalwrite(led3, HIGH);
    digitalwrite(led4, HIGH);
    digitalwrite(led5, LOW);
    digitalwrite(led6, LOW);
    ...
}
</code></pre>

<p>but that would be a big pile of code which could be way more efficient. Perhaps.. my code isn't even correct.</p>

<p>So how could this be more efficient or perhaps actually working?</p>

<hr>

<p><em>The whole code, here below.</em></p>

<pre><code>int cleanCount = 1000;
int softpotPin = A0; //analog pin 0



void setup () {
    Serial.begin(9600);
    digitalWrite(softpotPin, HIGH); //enable pullup resistor    
}


void loop() {
    int softpotReading = analogRead(softpotPin);
    if (softpotReading &lt; 980) { // IF AANGERAAKT
        digitalWrite(werktIeLED, HIGH); 
        ++cleanCount;
        Serial.println(cleanCount);
        delay(16); // 5x zo snel als leeglopen
    }
    else if (softpotReading &gt; 980) { // IF NIET AANGERAAKT
        digitalWrite(werktIeLED, LOW); 
        --cleanCount;
        Serial.println(cleanCount);
        delay(64); // 1000 / 60 seconden
    }
    else {      // Als er een fout optreed..
        Serial.println("Fout!");
        digitalWrite(werktIeLED, HIGH);    
        delay(250);               
        digitalWrite(werktIeLED, LOW);    
        delay(250);               
    }


}
</code></pre>
 2973: <p>Here is a suggestion with the led pins in an array that you loop over.</p>

<p>I suggest making the array global, so put it outside any functions (usually at the top):</p>

<pre><code>byte led_pins[] = {pin1, pin2, pin3, pin4, pin5, pin6, pin7, pin8};
</code></pre>

<p>Then put this in your loop (assumes that you have a <code>int</code> called cleanCount that is in scope:</p>

<pre><code>const int increment = 100;

for (int i = 0; i &lt; sizeof(led_pins) / sizeof(led_pins[0]); i++) {
  boolean onOrOff = cleanCount &gt; (i+1) * increment;
  digitalWrite(led_pins[i], onOrOff);
}
</code></pre>
 2944: <p>You can use the barGraph example from the Arduino code examples. This gives a bar-type graph and not point. I will give rough explination why it will work and the need not to re-invent the wheel.</p>

<pre><code>    int sensorReading = analogRead(analogPin);
  // map the result to a range from 0 to the number of LEDs:
  int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);

  // loop over the LED array:
  for (int thisLed = 0; thisLed &lt; ledCount; thisLed++) {
    // if the array element's index is less than ledLevel,
    // turn the pin for this element on:
    if (thisLed &lt; ledLevel) {
      digitalWrite(ledPins[thisLed], HIGH);
    } 
    // turn off all pins higher than the ledLevel:
    else {
      digitalWrite(ledPins[thisLed], LOW); 
    }
  }
</code></pre>

<p><code>int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);</code></p>

<p>This will give you the point in the array, 0-10, for 0-1000, if you replace <code>1023</code> with <code>1000</code></p>

<p>Simplified <code>map()</code> function:</p>

<p><code>int point = sensorReading*10/1000</code> this gives you a range of 0-10, the int keeps it from having decimal points.</p>

<p>As you can see from the for loop it turns on all the LEDs that are in the array to the end and then turns off those not needed.</p>
