changing variable in a loop

can you use a latching button or toggle swith as an input that changes the timer value of a loop?

can you use a latching button or toggle swith as an input that changes the timer value of a loop?

The Arduino programming language allows for this possibility. I am capable of using this capability to develop a program that counts up or down time, and change the amount of time to count, and to suspend/resume counting, based on switch states.

That you are asking such a basic question implies that you are not.

You'll need to expand on your requirements to get any more help, though.

PaulS:

can you use a latching button or toggle swith as an input that changes the timer value of a loop?

The Arduino programming language allows for this possibility. I am capable of using this capability to develop a program that counts up or down time, and change the amount of time to count, and to suspend/resume counting, based on switch states.

That you are asking such a basic question implies that you are not.

You’ll need to expand on your requirements to get any more help, though.

I am using an array to create a cycle of on offs. I would like a switch to change the speed of the delay instantly.
current code

int buttonPin = 2;     
int pinArray[] = {5, 6, 7, 8, 9, 10, 11, 12};     
int timer = 1000;
int count = 0;
int buttonState = 0;         
int buttonPushCounter = 0; 

void setup() {
  
for (count=0;count<8;count++) {
  pinMode(pinArray[count], OUTPUT); 
}  
  pinMode(buttonPin, INPUT); 
 Serial.begin(9600);  
}
void loop() {
  
  buttonState = digitalRead(buttonPin);
 
  if (buttonState == HIGH) 
    { for (count=0;count<8;count++) {
   digitalWrite(pinArray[count], HIGH);
   delay(timer);
   digitalWrite(pinArray[count], LOW);
   //delay(timer2)  
  Serial.println("on");
  Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter, DEC);}}
      else
   {Serial.print("off"); 
  }}

what I want o add

timer2 = digitalRead(toggle);
  if (toggle == HIGH)
  {
    (timer2 = 4000);
if (toggle == LOW);
  {
    (timer = 0);
  }
  }

I would like a switch to change the speed of the delay instantly.

Well, then, you'll need to read the switch state more often. Therefore, the delay() calls have to go. The blink without delay example should get you pointed in the right direction.

Also toggle is the pin number of the input, not the value it is currently at. You seem to be getting these two things mixed up in the second code you posted.

PaulS:

I would like a switch to change the speed of the delay instantly.

Well, then, you'll need to read the switch state more often. Therefore, the delay() calls have to go. The blink without delay example should get you pointed in the right direction.

can you show me an example of code that combines blink without delay with an array?