hi, thanks for help in advance.
I am tryinjgto learn Arduino programming. I want to make lots of blinky LEDs for two applications, One will be my next Christmas lights display, and two, wearable bling for my nieces.
So to that end I have been on here eliciting help, and have gotten a good deal of assistance. Recently, I had a light pattern I tried to set up, but there was no algorithm I could think of to give me exactly what I wanted. So I used a 2 dimensional array to provide the proper sequence.
It worked very well, only trouble is that the new code sequence is too fast! I know, I know, use millis()! I have tried, here is the code:
// Larson scanner with PWM
#define DEBUG_UART 0
const uint8_t ledPin[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; // PWM pins 2 through 13
const uint8_t totalNoLeds = sizeof(ledPin);
void twopattern()
{
static uint8_t actual = (totalNoLeds);
static uint32_t previousMillis = 0;
const uint16_t myIntervall = 100;
int patternij[17][12] = {
{255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255},
{75, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 75},
{50, 75, 255, 0, 0, 0, 0, 0, 0, 255, 75, 50},
{25, 50, 75, 255, 0, 0, 0, 0, 255, 75, 50, 25},
{10, 25, 50, 75, 255, 0, 0, 255, 75, 50, 25, 10},
{5, 10, 25, 50, 75, 255, 255, 75, 50, 25, 10, 5},
{0, 5, 10, 25, 50, 255, 255, 50, 25, 10, 5, 0},
{0, 0, 5, 10, 255, 75, 75, 255, 10, 5, 0, 0},
{0, 0, 0, 255, 75, 50, 50, 75, 255, 0, 0, 0},
{0, 0, 255, 75, 50, 25, 25, 50, 75, 255, 0, 0},
{0, 255, 75, 50, 25, 10, 10, 25, 50, 75, 255, 0},
{255, 75, 50, 25, 10, 5, 5, 10, 25, 50, 75, 255},
{75, 50, 25, 10, 5, 0, 0, 5, 10, 25, 50, 75},
{50, 25, 10, 5, 0, 0, 0, 0, 5, 10, 25, 50},
{25, 10, 5, 0, 0, 0, 0, 0, 0, 5, 10, 25},
{10, 5, 0, 0, 0, 0, 0, 0, 0, 0, 5, 10},
{5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5},
};
if (millis() - previousMillis >= myIntervall)
{
for (int j = 0; j < 17; j++)
{
for (int i = 0; i < 12; i++)
{
analogWrite(ledPin[i], patternij[j][i]);
delay(4);
}
}
#if DEBUG_UART
#endif
previousMillis = millis();
}
}
void setup()
{
for (uint8_t i = 0; i < totalNoLeds; i++)
{
pinMode(i, OUTPUT);
}
}
void loop()
{
twopattern();
}
I cannot figure out WHERE to put the millis(). If I put it where it is, the LEDs flash and then wait for the millis(), If I move it to after the ‘for’ loops, it never runs.
I am missing something. I tried putting the first dimension (rows, columns?) into a variable that updates on millis(), but it did not work well either.
Anyway, a bit of help and a second set of eyes on this program would be very welcome!
Roger Ayotte