int pinLED = 13;
byte LED;
byte oldStatusLED;
boolean statusLED_On = true;
byte status;
unsigned long lastBlink = 0;
unsigned long intervalBlink;
// declare a structure of pin and interval
struct DipSwitch
{
const uint8_t pin; // the gpio
const uint16_t interval; // the interval in seconds
};
// make an array of dipswitches and initialize the values
DipSwitch dipSwitch[]
{
{8, 2}, // calculate (2 * factor) = 20000
{12, 4}, // calculate (4 * factor) = 40000
};
// calculate the setted interval
uint32_t getInterval()
{
const uint16_t factor = 1000; // millis for seconds
uint32_t interval = 0;
for (auto &i : dipSwitch)
{
if (digitalRead(i.pin) == LOW) interval += i.interval;
}
return interval * factor;
}
void setup()
{
Serial.begin(115200);
for (auto &i : dipSwitch)
{
pinMode(i.pin, INPUT_PULLUP);
pinMode(pinLED, OUTPUT);
}
}
void loop()
{
//get interval
intervalBlink = getInterval();
//blink the led
if (millis() - lastBlink >= intervalBlink) {
lastBlink = millis();
digitalWrite(pinLED, !digitalRead(pinLED));
}
}