[solved] Cannot get a variable to update inside a loop

Hi.
I'm trying to get a delay to shorten everytime a while() sentence is running, but cannot for the life of me get it to work. I subtract a variable from another variable everytime the while() is running, but the delay() with the variable doesn't change. I was wondering if anyone could help me.

Here is the code:

CODE START:

const int input = A3;    
const int maxpin =  9; 
const int minpin = 1;
const int dly = 1000;
const int pause = 1000;
const int dlyfrac = 0.1;

int currentpin;
int dlycurrent;
int dlyminus;


int buttonState = 0;  

void setup() {
  
  pinMode(input, INPUT);
  
  dlyminus = (dlyfrac * dly);
  dlycurrent = dly;
  currentpin = minpin;
  while(currentpin <= maxpin)
  {
    pinMode(currentpin, OUTPUT);
    currentpin++;
    }
}

void loop() {

  buttonState = digitalRead(input);
  
  if (buttonState == HIGH) {
    
   currentpin = minpin;
   
    
    while(currentpin <= maxpin)
    {
      digitalWrite(currentpin, HIGH);
      delay(dlycurrent);
      digitalWrite(currentpin, LOW);
      currentpin++;
      dlycurrent = (dlycurrent - dlyminus);
      }
  
     currentpin = minpin;
     delay(pause);
   
  }
  
  else {
   
    currentpin = minpin;
    while(currentpin <= maxpin)
    {
      digitalWrite(currentpin, LOW);
      currentpin++;
      } 
      currentpin = minpin;
   
  }
}

CODE END:

If someone out there could help me figure this out, I would be greatful.

const int dlyfrac = 0.1;

Try

const float dlyfrac = 0.1;

You are mixing integers and floating points, that is why you code does not work.

int delay_current = 1000;
int delay_change = -100;

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
}

void loop()
{
  digitalWrite(LED_BUILTIN, HIGH);
  delay(delay_current);
  digitalWrite(LED_BUILTIN, LOW);
  delay(delay_current);
  delay_current += delay_change;
  if ((delay_current <= 0) || (delay_current >= 1000)) delay_change = -delay_change;
}

Thanks a LOT :slight_smile:
Sorry, I'm still kind of a newb to coding, that never crossed my mind.

Note that delay does not take floating points as argument, a value like 0.1 will be cast to an integer with a value of 0, so do not use float for delay.