Multiprogram warning light

Hi guys,

I'm trying to make a multiprogram warning light for inside my car. I wan't to use 5 led's with a kind of PWM modulation. Each PWM pulse is counted in a while loop. I want one button to push trough each case or different light setting. Since i constantly use the delay function, most of my pushes to switch case are ignored. I need a program that's constantly questioning the state of my switch and is able to switch case while in another case. I've tried different things but can't find a solution. I think i will need to work without a delay function, but i still wan't my "PWM" modulation to prevent my LED's from overheating(special LED's). My code is written in dutch but i mentioned my variabels in english so i hope you guys can understand some pieces of it. My second case has no PWM, just to test second case...

#include "Arduino.h"






int programma = 0; // case number
int knopstatus = LOW; // button status
int vorigeknopstatus = LOW; // last button status
unsigned int aantijd = 9; // on time PWM pulse
unsigned int uittijd = 1; // off time PWM pulse
long knipper = 0; // PWM counter
long knippering = 5000; // max PWM
int schakelaar = 13; // button pin

void setup(/* arguments */) {
 pinMode(2, OUTPUT);
 pinMode(3, OUTPUT);
 pinMode(4, OUTPUT);
 pinMode(5, OUTPUT);
 pinMode(6, OUTPUT);
 pinMode(13, INPUT);
}
void loop(/* arguments */) {
  knopstatus = digitalRead(schakelaar);

while ((knopstatus != vorigeknopstatus) && (knopstatus == HIGH)) {
programma++;
delay(200);
vorigeknopstatus = knopstatus;

}



 /* code */


switch (programma) {

  case 1:
  {

  do {
    digitalWrite(2, HIGH);
    delayMicroseconds(aantijd);
    digitalWrite(2, LOW);
    delayMicroseconds(uittijd);
    knipper++;
  } while(knipper < knippering);
  delay(100);
  knipper = 0;

  do {
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    delayMicroseconds(aantijd);
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    delayMicroseconds(uittijd);
    knipper++;
  } while(knipper < knippering);
  delay(50);
  knipper = 0;

  do {
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    delayMicroseconds(aantijd);
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    delayMicroseconds(uittijd);
    knipper++;
  } while(knipper < knippering);
  delay(100);
  knipper = 0;

  do {
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    delayMicroseconds(aantijd);
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
    delayMicroseconds(uittijd);
    knipper++;
  } while(knipper < knippering);
  delay(100);
  knipper = 0;

  do {
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    delayMicroseconds(aantijd);
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);

    delayMicroseconds(uittijd);
    knipper++;
  } while(knipper < knippering);
  delay(700);
  knipper = 0;
}
  break;

  case 2:
{
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  delay(200);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  delay(200);
}
  break;

  case 3:
{
  programma = 1;
}
  default:
  {
    programma = 1;
  }
  break;

}




}

i still wan't my "PWM" modulation to prevent my LED's from overheating(special LED's).

The first question you should be asking is "how do I limit the current to stop my leds overheating". PWM is not a good way to do this. Doing the PWM in software is making your code more difficult, and there is no need. Please post a link to the page where you purchased these "special" leds.

It are just 12v cob led's. With this simple pwm regulation. I can prevent them from overheating and regulated the lumen output. It's not more complicated i think? It just wouldn't work when i use a delay

With high current leds like those, you should use constant-current drivers to give them long life. Simply PWM-ing them may seem to keep them cooler but it is probably shortening their lives. With adjustable CC drivers you can control the lumen output.

I understand. In my case. I now use 10w cob chips. They don't become very hot because they blink constantly. With my "pwm"-ing it looks like i can control the lumen output. As i would like to control 10+ led seperatly. I would need an even amount of drivers is suppose? Since they are 10w each. They would draw 0.83A. Now they draw a peak current of 0.3A and give a high lumen output. Since i would like to use my own pcb to control it with arduino and drivers, is there any driver you could suggest me... thank you for your help!

PWM switches on and off. So your peak current will still be 0.83A when the led is on.