Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Pages: [1]   Go Down
Author Topic: Simulate a welding arc light  (Read 1019 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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;
   else
     value1 = LOW;

   digitalWrite(led1, value1);
 }

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

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

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

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 555
Posts: 27684
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Jump to: