Speed Control without delay !

With delay Code;

const int LEDPin[10] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
byte y=0;
long wait=1000;
byte SPEED_MOD=0;

void setup(){
 for(y=0; y<10; y++){
  pinMode(LEDPin[y], OUTPUT);
  }
 pinMode(2, INPUT_PULLUP);
 pinMode(13, OUTPUT);
 attachInterrupt(0, KESME, LOW);
}

void loop(){
 for(y=0; y<10; y++){
   digitalWrite(LEDPin[y], HIGH);
   delay(wait);
   digitalWrite(LEDPin[y], LOW);
  }
 }

void KESME(){
if(SPEED_MOD == 5){
  SPEED_MOD=0;
  }
  else{
   SPEED_MOD++;
   }
  if(SPEED_MOD == 0){
  wait=1000;
  }
  if(SPEED_MOD == 1){
  wait=700;
  }
  if(SPEED_MOD == 2){
  wait=500;
  }
  if(SPEED_MOD == 3){
  wait=200;
  }
  if(SPEED_MOD == 4){
  wait=100;
  }
  if(SPEED_MOD == 5){
  wait=50;
  }
}

I want without delay code. How do I make? :cry:
The end time does not pass to the other mode. :cry:

const int noLeds = 10;
const int LEDPin[noLeds] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
unsigned long mark;

void loop(){
  if(millis()>=mark){//check time mark
    mark += wait;//increase time mark
    digitalWrite(LEDPin[y++], 0);//turn previous led off
    if(y==noLeds) y = 0;//y=y%noLeds
    digitalWrite(LEDPin[y], 1);//turn next led on
  }//if(millis()>=mark)
}//loop()

Not Worked

const int noLeds = 10;
const int LEDPin[noLeds] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
unsigned long mark;

byte y=0;
long wait=100;
byte SPEED_MOD=0;

void setup(){
for(y=0; y<10; y++){
 pinMode(LEDPin[y], OUTPUT);
 }
pinMode(2, INPUT_PULLUP);
pinMode(13, OUTPUT);
attachInterrupt(0, KESME, LOW);
}

void loop(){
if(millis()>=mark){//check time mark
mark += wait;//increase time mark
   digitalWrite(LEDPin[y++], 0);//turn previous led off
   if(y==noLeds) y = 0;//y=y%noLeds
   digitalWrite(LEDPin[y], 1);//turn next led on
 }
}

void KESME(){
if(SPEED_MOD == 5){
 SPEED_MOD=0;
 }
 else{
  SPEED_MOD++;
  }
 if(SPEED_MOD == 0){
 wait=10000;
 }
 if(SPEED_MOD == 1){
 wait=700;
 }
 if(SPEED_MOD == 2){
 wait=500;
 }
 if(SPEED_MOD == 3){
 wait=200;
 }
 if(SPEED_MOD == 4){
 wait=100;
 }
 if(SPEED_MOD == 5){
 wait=50;
 }
}

NOT Work

OK, define "work".

Please use code tags when posting code.

Since you are using the global y variable in the for() loop in the setup() function y will start at 10 in you code.

veliusta:
Not Worked

So what do you think might be the problem.
Thinking is 99% of successful programming.

...R

I suggest you make y a local variable in the setup() function:

for(int y=0; y<noLeds; y++)pinMode(LEDPin[y], OUTPUT);

I did it. No Delay, No millis() :smiley:

const int LEDPin[10] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
byte y=0;
long BEKLE=150000;
byte SPEED_MOD=0;
unsigned long DOGRU_ZAMAN;
unsigned long DONGU_ZAMAN;

void setup(){
 for(y=0; y<10; y++){
  pinMode(LEDPin[y], OUTPUT);
  }
 pinMode(2, INPUT_PULLUP);
 pinMode(13, OUTPUT);
 attachInterrupt(0, KESME, LOW);
 y=0;
}

void loop(){
    DOGRU_ZAMAN = DOGRU_ZAMAN+1;
  if(DOGRU_ZAMAN >= (DONGU_ZAMAN + BEKLE)){
     if(y==0){digitalWrite(LEDPin[9], LOW);}
     digitalWrite(LEDPin[y], HIGH);
     digitalWrite(LEDPin[y]-1, LOW);
  if(y == 9){
   y=0;
  }else{
   y++;
  }
    DONGU_ZAMAN = DOGRU_ZAMAN;
  }
 }

void KESME(){
if(SPEED_MOD == 5){
  SPEED_MOD=0;
  }
  else{
   SPEED_MOD++;
   }
  if(SPEED_MOD == 0){
  BEKLE=150000;
  }
  if(SPEED_MOD == 1){
  BEKLE=75000;
  }
  if(SPEED_MOD == 2){
  BEKLE=50000;
  }
  if(SPEED_MOD == 3){
  BEKLE=25000;
  }
  if(SPEED_MOD == 4){
  BEKLE=10000;
  }
  if(SPEED_MOD == 5){
  BEKLE=5000;
  }
}

You should use millis() instead, what you have done is writing your own delay which blocks the cpu and does nothing useful except that is has far worse accuracy.