Hi All,
I am trying to adapt the Array Tutorial sketch to create an LED chaser effect. As the sketch uses Delay() I am trying to convert it to millis() for the first step.
Once I have the whole Thing running on Millis() I would like to make it so that the LED Array not just lit as High or Low, but something like:
LED-9 (Low)
LED-8 (Low)
LED-7 (High)
LED-6 (66% brightness)
LED-5 (33% brightnes)
LED-4 (Low)
LED-3 (Low)
LED-2 (Low)
LED-1 (Low)
Kind of like a Fading tail behind the lit LED.
That second step is just so you know where I want to go with this. for the Moment, I will be completely happy if I can get rid of the delay.
Here is the code that I have so far which works but with Delay. I have commented out all my Trials and Errors as they did not work.
/*
Arrays
Unlike the For Loop tutorial, where the pins have to be
contiguous, here the pins can be in any random order.
The circuit:
* LEDs from pins 2 through 7 to ground
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Array
*/
int timer = 250; // The higher the number, the slower the timing.
int ledPins[] = {
9, 10, 11, 12, 13 }; // an array of pin numbers to which LEDs are attached
int pinCount = 5; // the number of pins (i.e. the length of the array)
int midPin;
int lastPin;
int offPin;
unsigned long TIMER_Chaser = 0;
unsigned long INTERVAL_Chaser;
void setup() {
TIMER_Chaser = millis();
// the array elements are numbered from 0 to (pinCount - 1).
// use a for loop to initialize each pin as an output:
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
}
void loop() {
// delay with millis()
//if(millis() - TIMER_Chaser > INTERVAL_Chaser){
//loop from the lowest pin to the highest:
for (int thisPin = 0; thisPin < pinCount; thisPin++) { //lastPin = thisPin -1 etc.
/* midPin = thisPin--;
lastPin = midPin--;
offPin = lastPin--;
*/
digitalWrite(ledPins[thisPin], HIGH); // turn the pin on
/* analogWrite(ledPins[midPin], 168); // dim the pin after by 33%
analogWrite(ledPins[lastPin], 84); // dim the 2nd pin after by 66%
analogWrite(ledPins[offPin], LOW); // turn the pin off
TIMER_Chaser = millis(); */
delay(timer);
digitalWrite(ledPins[thisPin], LOW);
}
}
// }