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.