const int LED_PIN2 = 2;
const int LED_PIN3 = 3;
#define LED_ON HIGH
#define LED_OFF LOW
void setup() {
Serial.begin(115200);
pinMode(LED_PIN2, OUTPUT);
pinMode(LED_PIN3, OUTPUT);
digitalWrite(LED_PIN2, LED_OFF); // Give the output pins a definite, known state at start up
digitalWrite(LED_PIN3, LED_OFF);
Serial.println("Setup complete");
}
void loop() {
flashEqualOnOffPin2();
flashUnequalOnOffPin3();
}
void flashEqualOnOffPin2() {
uint32_t currentMillis = millis();
static uint32_t lastMillis;
const uint32_t onOffTime = 500; //Duration for LED to be on or off before changing state, in miliseconds
if (currentMillis - lastMillis >= onOffTime) {
lastMillis += onOffTime;
if (digitalRead(LED_PIN2) == LED_ON) {
digitalWrite(LED_PIN2, LED_OFF);
} else {
digitalWrite(LED_PIN2, LED_ON);
}
}
}
void flashUnequalOnOffPin3() {
uint32_t currentMillis = millis();
static uint32_t lastMillis;
const uint32_t onTime = 1750; //Duration for LED to be on, in miliseconds
const uint32_t offTime = 350; //Duration for LED to be off, in miliseconds
if (digitalRead(LED_PIN3) == LED_ON) { // Read the current state of pin 3
if (currentMillis - lastMillis >= onTime) { // Pin 3 is high (LED on), check on time and turn LED off if time has expired
lastMillis += onTime; // Add the value of onTime to lastMillis ready to start the next timing interval
digitalWrite(LED_PIN3, LED_OFF); // Turn LED off
}
} else {
if (currentMillis - lastMillis >= offTime) { // Pin 3 is low (LED off), check off time and turn LED on if time has expired
lastMillis += offTime; // Add the value of offTime to lastMillis ready to start the next timing interval
digitalWrite(LED_PIN3, LED_ON); // Turn LED on
}
}
}