Use PWM on an array

Hey All,
Thanks to this forum I now know how to blink multiple pins with an array
http://forum.arduino.cc/index.php?topic=185625.0

Next I'd like to use PWM on the array, I'm using an UNO so 3,5,6,9,10,11. I guess this means I would need to use analogWrite but I'm not sure how to do it. Any advice is appreciated.

int led1 = 3;
int led2 = 5;
int led3 = 6;
int led4 = 9;
int led5 = 10;
int led6 = 11;

int arrayPins[6] = {3, 5, 6, 9, 10, 11}; 

int arrayState = LOW;
int arrayLevel = 0;

void setup(){
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(11, OUTPUT);
}

void loop(){
  //  I'm using this with IR signals but I'm not including that code here to keep it simple,
  //  I've tried what I'm showing here and it doesn't work.
  
     case 1330: // Paus Button
      Serial.println("Up All - Pause Button");
      arrayLevel = arrayLevel + 5;
      if (arrayLevel > 0) arrayLevel = 0;
      arrayWriteAnalog(arrayPins, arrayLevel);
      break;

     case 1330: // Play Button
      Serial.println("Down All -  Play Button");
      arrayLevel = arrayLevel - 5;
      if (arrayLevel > 0) arrayLevel = 0;
      arrayWriteAnalog(arrayPins, arrayLevel);
      break;
}

 void arrayWriteAnalog(int pins[], int val) {
    for (int i = 0; i < 6; i++) {
      analogWrite(pins[i], val);
    } }
      if (arrayLevel > 0) arrayLevel = 0;
      arrayWriteAnalog(arrayPins, arrayLevel);

arrayLevel appears to be the value that you want to set the brightness of the LEDs to, so why set it to zero for any non zero value of arrayLevel ?

I guess this means I would need to use analogWrite but I'm not sure how to do it. Any advice is appreciated.

No.
If you use PWM the matrix refresh would not be synchronised to the PWM frequency and you will just get a random mess of blinking.
You need to write some code that does the PWM by hand as part of the refresh routine. That is each refresh is split up into say 16 steps where the LEDs that are on on each step are controlled by a brightness value.

By the way you have two case 1330: which wont work.

Mark

I do this in my LEDMux library (not for Arduino boards). The refresh routine contains a counter. If the counter value is less than the brightness value then set the LED(s) to the specified state. If it's greater than or equal to the brightness value, then force the LED(s) to be off.