I'm trying to blink a set of LED's. A time array is used to set the timing of each blink and another array selects the LED to blink.
I'm trying to use this library:
http://arduino.cc/playground/Code/Timertimer1.pulse(n[i]*2+20, 100, LOW);
This is supposed to make a LED blink once, i.e. turn the digital pin on for 100 ms and turn it off.
When I upload my code, the first LED's stay on for a lot longer than it's supposed to.
What am I doing wrong?
#include "Timer.h"
//select output pins
int led1 = 22;
int led2 = 24;
int led3 = 26;
int led4 = 28;
int led5 = 30;
int led6 = 32;
int led7 = 34;
int index = 7;
int start = 1;
Timer timer1;
long t1[] = {0,1000,2000,2000,3000,3000,4000,5000}; //type long to store big numbers (time in ms)
int n[]= {0,1,2,3,4,5,6,1};
void setup() {
// initialize digital pins 1-7 as an output.
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
// initialize serial:
Serial.begin(9600);
Serial.println("Ready");
//print what's currently in the arrays
Serial.println("Time Sequence");
int i;
for (i = 0; i < index; i = i + 1) {
Serial.println(t1[i]);
//Serial.println(n[i]);
}
}
void loop() {
timer1.update();
if(start == 1){
Serial.println("Starting Sequence...");
//output to pins
int i;
for (i = 1; i < index; i=i+1){
delay(t1[i]-t1[i-1]);
timer1.pulse(n[i]*2+20, 100, LOW);
timer1.update();
}
Serial.println(i);
if (i == index){
start = 0;
Serial.println("Sequence Stopped.");
}
}
}