Another multiples LEDs blinking question

Hi,
I swear, I did an extensive research on the subject but didn't really find what I'm looking for. Probably I didn''t understand the complex codes I've found ... I know absolutely nothing about coding !

So here is my question: I have 6 Powerswitch Tail for controlling AC lamps. Sure, the basic Blink sketch works perfectly but it's getting confusing when I wanted to add 5 more lamps. What I want to achieve is a separate sequence of on/off at variable time on each lamp. I'm looking for a code where I can easily change separately the duration on each lamp.

Here is an example :
Lamp 1 : _ _ _ __ _- - ______ -- ___ __ _ _
Lamp2 : _ _ _ ______ ___ --- ___ _ _ _ ___
Lamp3 : _ _ _ __ --- ---- ------ __ - - ____ ___ etc

here is a better example.

In my dream, I can copy the BLINK sketch for one LED on each lamp and I'd be happy but it didn't work...!

I'd really appreciate your help,

Thanks!
crispine

Instead of Blink, look at Blink Without Delay

What you want to do is complected for a beginner.
You want to have three or more independent blinking patterns, therefore you need a state machine.
http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html

This code performs random period blinking on some Christmas tree lights. Maybe this will give you and idea of the complexity you are looking at.
It works out a blinking rate for each LED, then blinks them at that rate. After so long it works out another set of blinking rates and does that. This will then repeat.

/* Random blinking lights
for use on a Christmas tree
By Mike Cook
*/

#define numberOfLights 16

byte pins[] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18};
byte pinState[numberOfLights];
long int changeTime[numberOfLights];
int flashRate[numberOfLights];
long flashChange;   // how often to change the flashing patterns

void setup() {
  for(int i = 0; i< numberOfLights; i++) {
    pinMode(pins[i], OUTPUT);
    changeTime[i] = millis() + random(1000, 200);
    pinState[i] = LOW;
  }
  setFlashTime();
}

void loop() {
  for(int i = 0; i < numberOfLights; i++) {
   if(changeTime[i] <= millis()) {
   pinState[i] = ~pinState[i];
   digitalWrite(pins[i], pinState[i]);
   changeTime[i] = millis() + flashRate[i];
   } 
  }
  if(flashChange <= millis()) setFlashTime();
}

void setFlashTime(){
  for(int i=0; i<numberOfLights; i++){
    flashRate[i] = random(200, 1500);
  }
  flashChange = millis() + 100000;  // next time to change pattern
}

Incidentally Peter - "Random Blinking Lights" is a song by the group "Delicate AWOL"

Thanks for your reply, I really appreciated it!

First AWOL: Thanks! I've found the code below. What I don't understand is how can I make a sequence with pin 13 and how can I add another LED running at the same time ?

/* Blink without Delay

Turns on and off a 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.

The circuit:

  • LED attached from pin 13 to ground.
  • Note: on most Arduinos, there is already an LED on the board
    that's attached to pin 13, so no hardware is needed for this example.

created 2005
by David A. Mellis
modified 8 Feb 2010
by Paul Stoffregen

This example code is in the public domain.

*/

// constants won't change. Used here to
// set pin numbers:
const int ledPin = 13; // the number of the LED pin

// Variables will change:
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000; // interval at which to blink (milliseconds)

void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
}

void loop()
{
// here is where you'd put code that needs to be running all the time.

// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
unsigned long currentMillis = millis();

if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;

// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;

// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}

Second: Thank Grumpy_Mike !

How can I change the sequence on each lamp so they will blink at the rhythm I want not in a random mode ?

For both questions you use an array that contains the sequence of delay times before the next step in the sequence.

Sorry for my ignorance but what is an array ?

There is no way I can copy that

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(11000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(5000); // wait for a second
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(2000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(3000); // wait for a second

}

and add the same code for pin12 and so one ?

  1. Look up 'blink without delay' in the learning > examples pages. Read it, understand it and adopt it.
  2. Look up 'State Machine' in the same pages.
  3. Look up 'array' in the reference page.

We're not going to write your program for you (unless you're willing to pay) but, if you get stuck, we'll help you sort out your errors.

Yes, thanks, this is what I am doing right now but also, I thought of the option to pay someone .

Not that I don't want to learn but the problem is, every time I need to use Arduino, I am in a rush and all the reading on coding doesn't have enough time to be assimilated, and I'm french speaking .

Hi,

So far... I'm not unhappy with what I've found (sketch below) and thanks to all of you for pointing me out where I should looking for. Array seems to be the solution. It still abstract tho ...

Now, I like this sequence I've got but is it possible to add another sequence following this one and make them in loop ?

I've remarked that when I change the order of pins and value on 'int count and timer' it makes different patterns. Instead of int pinArray[] = {11, 8, 7, 10, 9, 12};
int count = 1000;
int timer = 30;

I did
int pinArray[] = {12, 8, 10, 7, 9, 11};
int count = 500;
int timer = 60

I was hoping that copied the same code with different values would work but it didn't !
Any help would be appreciated.

Hope ...
Thanks!

/* Knight Rider 3
 * --------------
 *
 * This example concentrates on making the visuals fluid.
 *
 *
 * (cleft) 2005 K3, Malmo University
 * @author: David Cuartielles
 * @hardware: David Cuartielles, Aaron Hallborg
 */

int pinArray[] = {11, 8, 7, 10, 9, 12};
int count = 1000;
int timer = 30;

void setup(){
  for (count=0;count<6;count++) {
    pinMode(pinArray[count], OUTPUT);
  }
}

void loop() {
  for (count=0;count<5;count++) {
   digitalWrite(pinArray[count], HIGH);
   delay(timer);
   digitalWrite(pinArray[count + 6], HIGH);
   delay(timer);
   digitalWrite(pinArray[count], LOW);
   delay(timer*2);
  }
  for (count=5;count>0;count--) {
   digitalWrite(pinArray[count], HIGH);
   delay(timer);
   digitalWrite(pinArray[count - 1], HIGH);
   delay(timer);
   digitalWrite(pinArray[count], LOW);
   delay(timer*2);
  }
}

mhc0:
So far... I'm not unhappy with what I've found (sketch below) and thanks to all of you for pointing me out where I should looking for. Array seems to be the solution. It still abstract tho ...
Now, I like this sequence I've got but is it possible to add another sequence following this one and make them in loop ?

Only if you get rid of the delay()s.

I was hoping that copied the same code with different values would work but it didn't !
Any help would be appreciated.

But you haven't paid any attention to the help you've already been given.
Get rid of the delay()s and use the 'blink without delay' method instead. That's the ONLY way to achieve what you want.

Thanks Henry_Best for your reply.

I know it's obvious for you all but it's hard to understand when you are in the newbie side, but I'll get it !
Thanks everyone for your help. I appreciated that you take the time to answered my 'not exciting' questions ...! :slight_smile:

Oh and Grumpy_Mike, your website is a goldmine, thanks!

Cheers,