Hello. I need to make blink 3 leds every 5 minutes, when 1st led have own "ON time -duration", but 2nd and 3rd led have the same "ON time - duration".
No one of leds can not bee light up in the same time.
I cann not figure out how to run 1st cycle on o millis(), 2nd after 10000 millis, and 3rd 20000.
my testing code:
const int ledPin_1 = 8;// the number of the LED pin
int ledState_1 = LOW; // ledState_1 used to set the LED
int SolOnTime_1 = 200;
unsigned long ledStateOn_1;
unsigned long ledStateOff_1;
unsigned long previousMillis_1 = 0; // will store last time LED was updated
const long interval_1 = 5000; // interval_1 at which to blink (milliseconds)
const int ledPin_2 = 9;// the number of the LED pin
int ledState_2 = LOW; // ledState_2 used to set the LED
int SolOnTime_2 = 400;
unsigned long ledStateOn_2;
unsigned long ledStateOff_2;
unsigned long previousMillis_2; // will store last time LED was updated
const long interval_2 = 5000; // interval_2 at which to blink (milliseconds)
void setup() {
Serial.begin(9600);
pinMode(ledPin_1, OUTPUT);
pinMode(ledPin_2, OUTPUT);
}
void loop(){
led_1();
led_2();
}
//********************************** START led_1 ***************************************************************
void led_1(){
unsigned long currentMillis = millis();
if (currentMillis - previousMillis_1 >= interval_1) {
previousMillis_1 = currentMillis; //Serial.print(" previousMillis_1 = "); Serial.print(previousMillis_1);
if (ledState_1 == LOW) {
ledState_1 = HIGH;
ledStateOn_1 = millis(); //Serial.print(" ledStateOn_1 = "); Serial.print(ledStateOn_1);
Serial.print("sol_1 On = "); Serial.print(ledStateOn_1);
}
digitalWrite(ledPin_1, ledState_1);
}
if (millis() - ledStateOn_1 >= SolOnTime_1){
if (ledState_1 == HIGH){
ledState_1 = LOW;
ledStateOff_1 = millis(); //Serial.print(" ledStateOff_1 = "); Serial.println(ledStateOff_1);
Serial.print(" Off = "); Serial.println(ledStateOff_1);
}
digitalWrite(ledPin_1, ledState_1);
}
}
//********************************** END led_1 ***************************************************************
//********************************** START led_2 ***************************************************************
void led_2(){
unsigned long currentMillis = millis();
if (currentMillis - previousMillis_2 >= interval_2) {
previousMillis_2 = currentMillis; //Serial.print(" previousMillis_2 = "); Serial.print(previousMillis_2);
if (ledState_2 == LOW) {
ledState_2 = HIGH;
ledStateOn_2 = millis(); //Serial.print(" ledStateOn_2 = "); Serial.print(ledStateOn_2);
Serial.print("sol_2 On = "); Serial.print(ledStateOn_2);
}
digitalWrite(ledPin_2, ledState_2);
}
if (millis() - ledStateOn_2 >= SolOnTime_2){
if (ledState_2 == HIGH){
ledState_2 = LOW;
ledStateOff_2 = millis(); //Serial.print(" ledStateOff_2 = "); Serial.println(ledStateOff_2);
Serial.print(" Off = "); Serial.println(ledStateOff_2);
}
digitalWrite(ledPin_2, ledState_2);
}
}
//********************************** END led_2 ***************************************************************