Go Down

Topic: Simulate a welding arc light (Read 3194 times) previous topic - next topic


I'm a newbie. how do I blink the two leds at varying rates each separately. I can setup one led to blink on and off using delay but how do I do the same with 2 leds. I would like to have at least 10 high and 10 low with 10  different values of time for each one of the 10 high and ten low. 10 high and 10 low for each led.
This one i found just blinks each led at different rates is there a way to accomplish my goal with this sketch?

/* Blink Multiple LEDs without Delay
* Turns on and off several light emitting diode(LED) connected to a digital
* pin, without using the delay() function.  This means that other code
* can run at the same time without being interrupted by the LED code.
int led1 = 3;                // LED connected to digital pin 13
int led2 = 5;
int value1 = LOW;                // previous value of the LED
int value2 = LOW;                // previous value of the LED
long time1 = millis();
long time2 = millis();

long interval1 = 45;           // interval at which to blink (milliseconds)
long interval2 = 33;

void setup()
pinMode(led1, OUTPUT);      // sets the digital pin as output
pinMode(led2, OUTPUT);

void loop()
unsigned long m = millis();

if (m - time1 > interval1){
   time1 = m;

   if (value1 == LOW)
     value1 = HIGH;
     value1 = LOW;

   digitalWrite(led1, value1);

if (m - time2 > interval2){
   time2 = m;

   if (value2 == LOW)
     value2 = HIGH;
     value2 = LOW;

   digitalWrite(led2, value2);
any help would be greatly be appreciated


How about using random (min, max) to define the time intervals they are off and on?
Each time an LED completes one cycle, randomize its next turn on time.

Repeat your code for 10 LEDs, or set  it up as a loop and a couple of arrays to hold the on/off states and the randomized on/off times.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up