Controlling digital pin chase patterns via virtual pin with button widget

im new to coding and arduino but im building a project that requires the use of all 32 digital pins operating 2 16 channel relay packs. is there any way to create chase patterns within the code that I can then access via a virtual pin and button widget? I already have all of the buttons set to identify with their respective relays within the blynk app.

something like that ?

/*************** buttons *********************/
BLYNK_WRITE(V1)
{
  RelayBTN1 = param.asInt();
  if (RelayBTN1 == true) {
    digitalWrite(relay1, ON);
    Serial.println("relay1 on");
    led1.on();
    led2.off();

  }
  else {
    digitalWrite(relay1, OFF);
    Serial.println("relay1 off");
    led1.off();
    led2.on();
  }
}

BLYNK_WRITE(V2)
{
  RelayBTN2 = param.asInt();
  if (RelayBTN2 == true) {
    digitalWrite(relay2, ON);
    Serial.println("relay2 on");
    led3.on();
    led4.off();

  }
  else {
    digitalWrite(relay2, OFF);
    Serial.println("relay2 off");
    led3.off();
    led4.on();
  }
}

BLYNK_WRITE(V3)
{
  RelayBTN3 = param.asInt();
  if (RelayBTN3 == true) {
    digitalWrite(relay3, ON);
    Serial.println("relay3 on");
    led5.on();
    led6.off();

  }
  else {
    digitalWrite(relay3, OFF);
    Serial.println("relay3 off");
    led5.off();
    led6.on();
  }
}

and so on ....

that seems close. i should theoretically be able to modify that to turn on multiple relays in order and then off again yes?

yes you can easily :wink:

Chase patterns with relays sounds a bit of a strange approach to me. If you’re planning on switching relays on and off relatively quickly, you’ll fairly quickly kill the contacts. If you’re using 16 channel relay boards and you lose one or two relays then it will get expensive, or you’ll frequently be de-soldering the dead relays. In fact, some users of the forum have reported that many Chinese 8-way relay boards often arrive with at least one dodgy relay.

I would have thought that MOSFETS would be a better hardware solution, depending on what you’re switching of course.

Pete.