Hey Guys,

I’m currently working on an LED Arduino project that will control an 8x8 led matrix display and another number of LEDs to turn on and off in certain patterns. I’m relatively new to C++ so my coding is a small bit inefficient .

I’ve had a look at the LED & Multiplexing forum but I thought the Programming section would be more appropriate.

I basically would like to split the two top rows from the 8x8 matrix and have two led sections running independently i.e. a 2 x 8 matrix and a 6 x 8 matrix and maybe another few sections to be added later. I’ve created separate voids to deal with the lighting of these leds. The end result I was hoping for each section to run “simultaneously”.

After a bit of research I see this is impossible and I could only make it appear like its simultaneous by using timers. I have looked through various tutorials(e.g. http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay) about timers and I think I understand the basics but on implementation of a timer into my code it becomes a little funky.

The led sequences are finishing one iteration before being interrupted by another sequence and it just loops.

I can’t seem to figure out whats wrong with the timers? I think it may be something in the voids themselves. If someone could point me in the right direction I’d be grateful.

Thanks in advance.

```
unsigned long lastEarFrame = 0;
unsigned long lastCheekFrame = 0;
unsigned long lastChinFrame = 0;
unsigned int earSpeed = 300;
unsigned int cheekSpeed = 150;
unsigned int chinSpeed = 200;
int k, p, n, t, m, m1;
int cheekAnimation = 1;
int count = 0;
#include "TrueRandom.h"
#include "LedControl.h" // need the library
LedControl lc = LedControl(12, 11, 10, 1);
void setup() {
//Set some pins as outputs for ears - 5 for 5 Leds
Serial.begin(115200);
// Max7219 Code
lc.shutdown(0, false);
lc.setIntensity(0, 15);
lc.clearDisplay(0);
}
void loop() {
unsigned long currentTime = millis();
// check to see if its time to animate the ear
if(currentTime > (lastEarFrame+earSpeed))
{
animateEar();
lastEarFrame = currentTime;
}
// check to see if its time to animate the cheek
if(currentTime > (lastCheekFrame+cheekSpeed))
{
animateCheek();
lastCheekFrame = currentTime;
}
// check to see if its time to animate the chin leds
if(currentTime > (lastChinFrame+chinSpeed))
{
animateChin();
lastChinFrame = currentTime;
}
}
void animateEar()
{
// To be created
}
void animateCheek() {
if (count >= 4)
{
cheekAnimation++;
count = 0;
}
if (cheekAnimation > 4)// Number should be equal to number of cases in switch below.
{
cheekAnimation = 1;
}
switch (cheekAnimation)
{
case 1: OneWay(); break;
case 2: TwoWay(); break;
case 3: OneWayReverse(); break;
case 4: TwoWayReverse(); break;
//default: OneWay(); break;
}
}
void OneWay()
{
for (m = 0; m <= 7; m++) {
lc.setLed(0, 0, m, true);
lc.setLed(0, 1, m, true);
delay (cheekSpeed);
lc.setLed(0, 0, m, false);
lc.setLed(0, 1, m, false);
}
count++;
}
void TwoWay()
{
for (m = 0; m <= 7; m++) {
lc.setLed(0, 0, m, true);
lc.setLed(0, 1, abs(m - 7), true);
delay (cheekSpeed);
lc.setLed(0, 0, m, false);
lc.setLed(0, 1, abs(m - 7), false);
}
count++;
}
void OneWayReverse()
{
for (m = 0; m <= 13; m++) {
lc.setLed(0, 0, abs(m - 7), true);
lc.setLed(0, 1, abs(m - 7), true);
delay (cheekSpeed);
lc.setLed(0, 0, abs(m - 7), false);
lc.setLed(0, 1, abs(m - 7), false);
}
count++;
}
void TwoWayReverse()
{
for (m = 0; m <= 13; m++) {
if (m < 7) {
m1 = m;
}
else {
m1 = 14 - m;
}
lc.setLed(0, 0, m1, true);
lc.setLed(0, 1, abs(m - 7), true);
delay (cheekSpeed);
lc.setLed(0, 0, m1, false);
lc.setLed(0, 1, abs(m - 7), false);
}
count++;
}
void animateChin()
{// cant use set column and set led together. chin and cheek clash.
int randnumber = TrueRandom.random(2,8);// 2 to avoid the first two rows and 8 because (8-1 = 7) and 7 is the last row.
//p += led_bit[k];
for (k = 7;k >= randnumber; k--){
lc.setLed(0, k, 0, true);
lc.setLed(0, k, 1, true);
lc.setLed(0, k, 2, true);
lc.setLed(0, k, 3, true);
lc.setLed(0, k, 4, true);
lc.setLed(0, k, 5, true);
lc.setLed(0, k, 6, true);
lc.setLed(0, k, 7, true);
delay(chinSpeed);
}
for (k = randnumber; k <= 7; k++) {
// p -= led_bit[k];
lc.setLed(0, k, 0, false);
lc.setLed(0, k, 1, false);
lc.setLed(0, k, 2, false);
lc.setLed(0, k, 3, false);
lc.setLed(0, k, 4, false);
lc.setLed(0, k, 5, false);
lc.setLed(0, k, 6, false);
lc.setLed(0, k, 7, false);
delay(chinSpeed);
}
//k = 0;
}
```