here my progress.
i have an array of 16 pins that each are at a different dimming stage.
i found one solution to gbulmer suggestion for eliminating the digitalWrite(). which is using gpio_write_bit(GPIOA, LED_BIT_ARRAY[i],dimStates[i]);
next would be to look in to writing to the whole port at once.
#include <gpio.h>
volatile unsigned int counter = 0;
unsigned long myTimer = 0;
int dim = 0;
int dir = 1;
int ledAmt = 16;
int counterLimit = 160;
boolean dimStates [] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
volatile int dimValue [] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
const char ledPin[] = {
15,16,17,18,19,20,21,22,27,28,29,30,31,0,1,6};
const int LED_PORTref_ARRAY[] = {
1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0};
const int LED_BIT_ARRAY[] = {
7,6,5,4,3,15,14,13,8,15,14,13,12,11,10,5};
//15 ,16 ,17 ,18 ,19 ,20 ,21 ,22 ,27 ,28 ,29 ,30 ,31 ,0 ,1 ,6
//b7 ,b6 ,b5 ,b4 ,b3 ,a15 ,a14 ,a13 ,a8 ,b15 ,b14 ,b13 ,b12 ,b11 ,b10 ,a5
int dimDir [] = {
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
void handler_t(void) {
for(int i=0; i<ledAmt; i++){
if(dimValue[i] > counter){
dimStates[i] = true;
}
else{
dimStates[i] = false;
}
if(LED_PORTref_ARRAY[i] == 0) gpio_write_bit(GPIOA, LED_BIT_ARRAY[i],dimStates[i]);
if(LED_PORTref_ARRAY[i] == 1) gpio_write_bit(GPIOB, LED_BIT_ARRAY[i],dimStates[i]);
//digitalWrite(ledPin[i],dimStates[i]);
}
counter++;
if(counter > counterLimit) counter = 0;
}
void setup(void) {
for(int i=0; i<ledAmt; i++){
pinMode(ledPin[i],OUTPUT);
dimValue[i] = counterLimit/ledAmt * i;
}
pinMode(BOARD_LED_PIN,OUTPUT);
Timer2.setPrescaleFactor(1);
Timer2.setOverflow(500); //1079);
Timer2.attachCompare1Interrupt(handler_t);
}
void loop(void) {
if(millis() - myTimer > 15){
myTimer = millis();
toggleLED();
for(int i=0; i<ledAmt; i++){
dimValue[i] += dimDir[i];
if(dimValue[i] > counterLimit || dimValue[i] == 0) dimDir[i] = -dimDir[i];
}
}
}