Set the blink period to 0.33 seconds (333ms).Start with the standard blink without delay example for a single LED.You need to recognise that the patterns for both LEDs share a common divisor of 0.333 seconds. If you require that both LEDs are synchronised then here is another which involves minimal code, but still builds on the standard BWD example. Indexes = 0 //reset period index for this LEDĪs usual there are any number of ways to solve this problem. If (periods] = 0) //if next period is zero (end of sequence) StartTimes = currentTime //save start time of state zero indicates end of sequenceįor (int led = 0 led = periods]) //? time to change ?ĭigitalWrite(ledPins, !digitalRead(ledPins)) //flip led state Unsigned long periods = //periods for each LED. Take a look at this example that I wrote to answer a query a while ago const byte ledPins = PreviousMillis2 = currentMillis // Remember the timeĭigitalWrite(ledPin2, ledState2) // Update the actual LEDĮlse if ((ledState2 = LOW) & (currentMillis - previousMillis2 >= OffTime2)) If((ledState2 = HIGH) & (currentMillis - previousMillis2 >= OnTime2)) PreviousMillis1 = currentMillis // Remember the timeĭigitalWrite(ledPin1, ledState1) // Update the actual LEDĮlse if ((ledState1 = LOW) & (currentMillis - previousMillis1 >= OffTime1)) ![]() If((ledState1 = HIGH) & (currentMillis - previousMillis1 >= OnTime1)) check to see if it's time to change the state of the LED Long OffTime2 = 400 // milliseconds of off-time Long OnTime2 = 330 // milliseconds of on-time Unsigned long previousMillis2 = 0 // will store last time LED was updated Int ledState2 = LOW // ledState used to set the LED Int ledPin2 = 7 // the number of the LED pin Long OffTime1 = 750 // milliseconds of off-time Long OnTime1 = 250 // milliseconds of on-time Unsigned long previousMillis1 = 0 // will store last time LED was updated Int ledState1 = LOW // ledState used to set the LED Int ledPin1 = 4 // the number of the LED pin These variables store the flash pattern Right now I'm working off the "millis() for timing" tutorial which, as I said, old allows a single on and off time to be set (I need a no delay solution because I'll be having other LEDs fading and blinking independently). 33 of a second, and the go off the remaining. At the same time a second set of LEDS should be off at the start for 1.33 seconds, flash for. What I what is a set of LEDs to turn on for a second, then off for a second. ![]() At the moment every tutorial I've found has had a single on/off state. I have a couple of LEDs that I'd like to turn off and on in a sequence, but I'm having trouble finding out how to have multiple on/off states for each.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |