Independent LED blinking at the same time

Hello! As the subject of this topic says, I am trying to make 2 LEDs blink at the same time independently at different rates. I found the code on the Internet to do this and it works fine but I also need to introduce a button so, for example, if I press it once to blink the LEDs 120 times per minute at a rate of 50% on time and 50% off time, and if I press it twice to blink for example 120 times per minute 60% on and 40% off. I also would like to save the last setting automatically so when Arduino resets or turned off to start with the last setting used before.
As I said before, I have already the code to make the LEDs blink at the desired rates and independently but I have no idea how to write the code for the button. By the way, I am a beginner. I would appreciate a lot your help or suggestions.
Here is the code I found on the Internet:

int ledPin1 =  12;      // the number of the LED pin
int ledState1 = LOW;             // ledState used to set the LED
unsigned long previousMillis1 = 0;        // will store last time LED was updated
long OnTime1 = 250;           // milliseconds of on-time
long OffTime1 = 750;          // milliseconds of off-time
 
int ledPin2 =  13;      // the number of the LED pin
int ledState2 = LOW;             // ledState used to set the LED
unsigned long previousMillis2 = 0;        // will store last time LED was updated
long OnTime2 = 330;           // milliseconds of on-time
long OffTime2 = 400;          // milliseconds of off-time
 
void setup() 
{
  // set the digital pin as output:
  pinMode(ledPin1, OUTPUT);      
  pinMode(ledPin2, OUTPUT);      
}
 
void loop()
{
  // check to see if it's time to change the state of the LED
  unsigned long currentMillis = millis();
 
  if((ledState1 == HIGH) && (currentMillis - previousMillis1 >= OnTime1))
  {
    ledState1 = LOW;  // Turn it off
    previousMillis1 = currentMillis;  // Remember the time
    digitalWrite(ledPin1, ledState1);  // Update the actual LED
  }
  else if ((ledState1 == LOW) && (currentMillis - previousMillis1 >= OffTime1))
  {
    ledState1 = HIGH;  // turn it on
    previousMillis1 = currentMillis;   // Remember the time
    digitalWrite(ledPin1, ledState1);	  // Update the actual LED
  }
  
  if((ledState2 == HIGH) && (currentMillis - previousMillis2 >= OnTime2))
  {
    ledState2 = LOW;  // Turn it off
    previousMillis2 = currentMillis;  // Remember the time
    digitalWrite(ledPin2, ledState2);  // Update the actual LED
  }
  else if ((ledState2 == LOW) && (currentMillis - previousMillis2 >= OffTime2))
  {
    ledState2 = HIGH;  // turn it on
    previousMillis2 = currentMillis;   // Remember the time
    digitalWrite(ledPin2, ledState2);	  // Update the actual LED
  }
}

led_blinking.ino (1.87 KB)

Do you know how to read the state of an input pin ?

yes I do

I read so often on this forum, "I found the code on the Internet" and every time I read it, the hair on my head rolls over in it's grave. There is so much bad code on the Internet. It is bad because it doesn't make it easy for new coders to modify. Since you are new, I am hoping that reading my opinion of good code might help you more than the plethora of bad code. I am hoping you might learn how to structure a program to be easily adaptable. There are a lot of concepts in my code that I've added to the code you presented. I would encourage you to study each concept and know what each word, means and why it's there. Study my code. Run it. Fix it if it's not perfect. Ask questions if you like. You should be able to easily see from my code how index led2 using a separate push button from led1.

const byte Led1Pin =  12;      // the number of the LED pin
// ledState used to set the LED ----- MOVED to blinkLED1() function
// will store last time LED was updated ----- MOVED to blinkLED1() function
const unsigned long OnTime1[10] = {50UL, 100UL, 150UL, 200UL, 250UL, 300UL, 350UL, 400UL, 450UL, 500UL};           // array of milliseconds of on-time
// milliseconds of off-time ----- since you want duty cycle, we must derive it from on time based on duty cycle
const unsigned long DutyCycle1 = 1000UL;

const byte Led2Pin =  13;      // the number of the LED pin
// ledState used to set the LED ----- MOVED to blinkLED2() function
// will store last time LED was updated ----- MOVED to blinkLED2() function
const unsigned long OnTime2[10] = {600UL, 540UL, 480UL, 420UL, 360UL, 300UL, 240UL, 180UL, 120UL, 60UL};           // array of milliseconds of on-time
// milliseconds of off-time -----  since you want duty cycle, we must derive it from on time based on duty cycle
const unsigned long DutyCycle2 = 1200UL;

const byte PushButtonPin = 11;      // the number of the push button pin
const byte PushButtonTriggerState = LOW;      // the acvtive state of the push button
byte pushButtonIndex;      // will store button presses in sequence up to 10 and index on time array



void setup() {
  // set the digital pin as output:
  pinMode(Led1Pin, OUTPUT);
  pinMode(Led2Pin, OUTPUT);
  // set the ditial pin as input with internal pullup enabled:
  pinMode(PushButtonPin, INPUT_PULLUP);
}

void loop() {
  if (pushButton()) {
    if (pushButtonIndex >= 9) pushButtonIndex = 0;
    else pushButtonIndex++;
  }
  blinkLED1(pushButtonIndex);
  blinkLED2(pushButtonIndex);
}

void blinkLED1(byte index) {
  static byte ledState = LOW;
  static unsigned long ledTimestamp = 0;
  if (ledState == HIGH) {
    if (millis() - ledTimestamp >= OnTime1[index]) {
      ledState = LOW;
      digitalWrite(Led1Pin, ledState);
      ledTimestamp += DutyCycle1 - OnTime1[index];
    }
  }
  else {     // ledState == LOW
    if (millis() - ledTimestamp >= DutyCycle1 - OnTime1[index]) {
      ledState = HIGH;
      digitalWrite(Led1Pin, ledState);
      ledTimestamp = OnTime1[index];
    }
  }
}

void blinkLED2(byte index) {
  static byte ledState = LOW;
  static unsigned long ledTimestamp = 0;
  if (ledState == HIGH) {
    if (millis() - ledTimestamp >= OnTime2[index]) {
      ledState = LOW;
      digitalWrite(Led2Pin, ledState);
      ledTimestamp += DutyCycle2 - OnTime2[index];
    }
  }
  else {     // ledState == LOW
    if (millis() - ledTimestamp >= DutyCycle2 - OnTime2[index]) {
      ledState = HIGH;
      digitalWrite(Led2Pin, ledState);
      ledTimestamp += OnTime2[index];
    }
  }
}

bool pushButton() {
  static int lastButtonState;
  static unsigned long buttonDebounceTimestamp = 0;
  int buttonState = digitalRead(PushButtonPin);
  if (buttonState != lastButtonState && buttonState == PushButtonTriggerState) {
    if (millis() - buttonDebounceTimestamp >= 250UL) {// 250UL = 250ms = time for debounce
      lastButtonState = buttonState;
      buttonDebounceTimestamp = millis();
      return true;
    }
  }
  else {
    lastButtonState = buttonState;
    return false;
  }
}

Thank you, sir! I really appreciate your help! I will try the code and see how it works.