El código de transferencia de Arduino Uno / ATMega328P a ATTiny85 no funciona, ¿demasiadas variables?

1

Tengo un Arduino Uno y estoy ejecutando un boceto con muchas variables (23 matrices de caracteres constantes que tienen 54 objetos en cada matriz). Junto con todas estas variables hay muchas declaraciones if. El proyecto controla una tira de neopixel LED RGB donde cada LED es independiente (basado en WS2812). Este código funciona bien debajo del Uno y los LED parpadean como se espera. Sin embargo, cuando puse el código en el ATtiny85, todos parpadean al azar o algunos se encienden y permanecen encendidos. El código compila y carga sin errores en el Attiny85. ¿No estoy seguro de qué está sucediendo y que no funcionará? Cualquier ayuda es muy apreciada!

Estoy definiendo los arreglos como const char arrayName[] = y me preguntaba si ese es el problema porque hay tantos?

El código es para hacer un reloj de palabra LED RGB. La razón por la que me gustaría usar un Attiny es 1. Ya lo tengo (pero podría comprar otra cosa que no sea totalmente inaceptable). y 2. es lo suficientemente pequeño como para caber en el caso.

Podría comprar otro chip, pero me gustaría entender las limitaciones y por qué no funciona antes de comprar otro chip.

Si no es posible hacer que esto funcione en el Attiny85, ¿existe un pequeño chip alternativo que funcione?

A continuación se muestra el código, con la excepción de que en este momento está configurado para la impresión en serie en lugar de la salida real del LED RGB. ¿Hay alguna forma más eficiente de resolver el problema?

const char it[] =      {'1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char is[] =      {'0','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char mten[] =    {'0','0','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char half[] =    {'0','0','0','0','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char twenty[] =  {'0','0','0','0','0','0','1','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char quarter[] = {'0','0','0','0','0','0','0','0','0','1','1','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char mfive[] =   {'0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char minutes[] = {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char two[] =     {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char one[] =     {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char to[] =      {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char past[] =    {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char three[] =   {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char four[] =    {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char five[] =    {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char eight[] =   {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char seven[] =   {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char six[] =     {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char nine[] =    {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','0','0','0','0','0','0','0','0','0','0','0'};
const char ten[] =     {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','0','0','0','0','0','0','0','0','0'};
const char eleven[] =  {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','1','0','0','0','0','0','0'};
const char oclock[] =  {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','1','0','0','0'};
const char twelve[] =  {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','1'};

char pins[55] =  {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','
const char it[] =      {'1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char is[] =      {'0','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char mten[] =    {'0','0','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char half[] =    {'0','0','0','0','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char twenty[] =  {'0','0','0','0','0','0','1','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char quarter[] = {'0','0','0','0','0','0','0','0','0','1','1','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char mfive[] =   {'0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char minutes[] = {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char two[] =     {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char one[] =     {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char to[] =      {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char past[] =    {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char three[] =   {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char four[] =    {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char five[] =    {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char eight[] =   {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char seven[] =   {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char six[] =     {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0'};
const char nine[] =    {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','0','0','0','0','0','0','0','0','0','0','0'};
const char ten[] =     {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','0','0','0','0','0','0','0','0','0'};
const char eleven[] =  {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','1','0','0','0','0','0','0'};
const char oclock[] =  {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','1','0','0','0'};
const char twelve[] =  {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','1'};

char pins[55] =  {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','%pre%'};

int red = 50;
int grn = 0;
int blu = 0;

uint8_t oldminute = 0;

void setup () {  

}

void editPins(const char add[]) {
  for (int a = 0; a < 54; a++) {
    if (add[a] == '1') {
      pins[a] = '1';
    }
  }
}

void loop () {
  uint8_t hourvalue, minutevalue;

  hourvalue = 8;
  minutevalue = 13;

  for (int x = 0; x < 55; x++) {
    pins[x] = '0';
  }

    if ((minutevalue>4) && (minutevalue<10)) { 
      editPins(mfive); 
      editPins(minutes);
    } 
    if ((minutevalue>9) && (minutevalue<15)) { 
      editPins(mten); 
      editPins(minutes);
    }
    if ((minutevalue>14) && (minutevalue<20)) {
      editPins(quarter);
    }
    if ((minutevalue>19) && (minutevalue<25)) { 
      editPins(twenty);
      editPins(minutes);
    }
    if ((minutevalue>24) && (minutevalue<30)) { 
      editPins(twenty);
      editPins(mfive);
      editPins(minutes);
    }  
    if ((minutevalue>29) && (minutevalue<35)) {
    editPins(half);
    }
    if ((minutevalue>34) && (minutevalue<40)) { 
      editPins(twenty);
      editPins(mfive);
      editPins(minutes);
    }  
    if ((minutevalue>39) && (minutevalue<45)) { 
      editPins(twenty);
      editPins(minutes);
    }
    if ((minutevalue>44) && (minutevalue<50)) {
      editPins(quarter);
    }
    if ((minutevalue>49) && (minutevalue<55)) { 
      editPins(mten);
      editPins(minutes);
    } 
    if (minutevalue>54) { 
      editPins(mfive);
      editPins(minutes);
    }

    if ((minutevalue <5)) {
      if (hourvalue==1) { 
        editPins(one);
      }
      if (hourvalue==2) { 
        editPins(two);
      }
      if (hourvalue==3) { 
        editPins(three);
      }
      if (hourvalue==4) { 
        editPins(four);
      }
      if (hourvalue==5) { 
        editPins(five);
      }
      if (hourvalue==6) { 
        editPins(six);
      }
      if (hourvalue==7) { 
        editPins(seven);
      }
      if (hourvalue==8) { 
        editPins(eight);
      }
      if (hourvalue==9) { 
        editPins(nine);
      }
      if (hourvalue==10) { 
        editPins(ten);
      }
      if (hourvalue==11) { 
        editPins(eleven);
      }
      if (hourvalue==12) { 
        editPins(twelve);
      }
      editPins(oclock);
    } else
      if ((minutevalue < 35) && (minutevalue >4)) {
        editPins(past);
        if (hourvalue==1) { 
          editPins(one);
        }
        if (hourvalue==2) { 
          editPins(two);
        }
        if (hourvalue==3) { 
          editPins(three);
        }
        if (hourvalue==4) { 
          editPins(four);
        }
        if (hourvalue==5) { 
          editPins(five);
        }
        if (hourvalue==6) { 
          editPins(six);
        }
        if (hourvalue==7) { 
          editPins(seven);
        }
        if (hourvalue==8) { 
          editPins(eight);
        }
        if (hourvalue==9) { 
          editPins(nine);
        }
        if (hourvalue==10) { 
          editPins(ten);
        }
        if (hourvalue==11) { 
          editPins(eleven);
        }
        if (hourvalue==12) { 
          editPins(twelve);
        }

      } else {
        // if we are greater than 34 minutes past the hour then display
        // the next hour, as we will be displaying a 'to' sign
        editPins(to);
        if (hourvalue==1) { 
          editPins(two);
        }
        if (hourvalue==2) { 
          editPins(three);
        }
        if (hourvalue==3) { 
          editPins(four);
        }
        if (hourvalue==4) { 
          editPins(five);
        }
        if (hourvalue==5) { 
          editPins(six);
        }
        if (hourvalue==6) { 
          editPins(seven);
        }
        if (hourvalue==7) { 
          editPins(eight);
        }
        if (hourvalue==8) { 
          editPins(nine);
        }
        if (hourvalue==9) { 
          editPins(ten);
        }
        if (hourvalue==10) { 
          editPins(eleven);
        }
        if (hourvalue==11) { 
          editPins(twelve);
        }
        if (hourvalue==12) { 
          editPins(one);
        }
      } 

      for (int x = 0; x < 54; x++) {
        if (pins[x]=='1') {
          Serial.println(x);
        }
      }
      delay(5000);
}
'}; int red = 50; int grn = 0; int blu = 0; uint8_t oldminute = 0; void setup () { } void editPins(const char add[]) { for (int a = 0; a < 54; a++) { if (add[a] == '1') { pins[a] = '1'; } } } void loop () { uint8_t hourvalue, minutevalue; hourvalue = 8; minutevalue = 13; for (int x = 0; x < 55; x++) { pins[x] = '0'; } if ((minutevalue>4) && (minutevalue<10)) { editPins(mfive); editPins(minutes); } if ((minutevalue>9) && (minutevalue<15)) { editPins(mten); editPins(minutes); } if ((minutevalue>14) && (minutevalue<20)) { editPins(quarter); } if ((minutevalue>19) && (minutevalue<25)) { editPins(twenty); editPins(minutes); } if ((minutevalue>24) && (minutevalue<30)) { editPins(twenty); editPins(mfive); editPins(minutes); } if ((minutevalue>29) && (minutevalue<35)) { editPins(half); } if ((minutevalue>34) && (minutevalue<40)) { editPins(twenty); editPins(mfive); editPins(minutes); } if ((minutevalue>39) && (minutevalue<45)) { editPins(twenty); editPins(minutes); } if ((minutevalue>44) && (minutevalue<50)) { editPins(quarter); } if ((minutevalue>49) && (minutevalue<55)) { editPins(mten); editPins(minutes); } if (minutevalue>54) { editPins(mfive); editPins(minutes); } if ((minutevalue <5)) { if (hourvalue==1) { editPins(one); } if (hourvalue==2) { editPins(two); } if (hourvalue==3) { editPins(three); } if (hourvalue==4) { editPins(four); } if (hourvalue==5) { editPins(five); } if (hourvalue==6) { editPins(six); } if (hourvalue==7) { editPins(seven); } if (hourvalue==8) { editPins(eight); } if (hourvalue==9) { editPins(nine); } if (hourvalue==10) { editPins(ten); } if (hourvalue==11) { editPins(eleven); } if (hourvalue==12) { editPins(twelve); } editPins(oclock); } else if ((minutevalue < 35) && (minutevalue >4)) { editPins(past); if (hourvalue==1) { editPins(one); } if (hourvalue==2) { editPins(two); } if (hourvalue==3) { editPins(three); } if (hourvalue==4) { editPins(four); } if (hourvalue==5) { editPins(five); } if (hourvalue==6) { editPins(six); } if (hourvalue==7) { editPins(seven); } if (hourvalue==8) { editPins(eight); } if (hourvalue==9) { editPins(nine); } if (hourvalue==10) { editPins(ten); } if (hourvalue==11) { editPins(eleven); } if (hourvalue==12) { editPins(twelve); } } else { // if we are greater than 34 minutes past the hour then display // the next hour, as we will be displaying a 'to' sign editPins(to); if (hourvalue==1) { editPins(two); } if (hourvalue==2) { editPins(three); } if (hourvalue==3) { editPins(four); } if (hourvalue==4) { editPins(five); } if (hourvalue==5) { editPins(six); } if (hourvalue==6) { editPins(seven); } if (hourvalue==7) { editPins(eight); } if (hourvalue==8) { editPins(nine); } if (hourvalue==9) { editPins(ten); } if (hourvalue==10) { editPins(eleven); } if (hourvalue==11) { editPins(twelve); } if (hourvalue==12) { editPins(one); } } for (int x = 0; x < 54; x++) { if (pins[x]=='1') { Serial.println(x); } } delay(5000); }
    
pregunta Elmer

2 respuestas

1

Primero, la diferencia entre el ATmega328p usado en el Uno, y el ATtiny es principalmente (para sus propósitos de todos modos), la cantidad de memoria y flash disponibles. El ATmega328p tiene 32KB Flash y 2KB SRAM. El ATtiny85 tiene un cuarto de ambos, a 8KB Flash y 0.5KB SRAM.

Segundo, mientras usa la palabra clave Const, como han señalado otros, esto funciona de manera diferente en Arduino / avr-gcc que en otros microcontroladores. Mi favorito personal, el MSP430, usa Const para escribir la variable como solo lectura, en el espacio de código, no en la memoria RAM. La implementación de Arduino no lo hace. Después de leer enlace , parece que el método de Arduino para hacer esto es un poco más complejo de lo que personalmente me interesa bucear. Pero ...

Tercero, su problema radica principalmente en la matriz de caracteres muy ineficiente que está utilizando. Es un cerdo de memoria. Además de la memoria necesaria para los globales, y el uso de la biblioteca Arduino, sus 23 matrices de 54 caracteres cada una toman 1242 bytes. Se consumen 1.2 KB de memoria, ya que cada carácter en la matriz de caracteres ocupa un mínimo de un byte de 8 bits. ¡No es de extrañar que el ATtiny tenga un pequeño ataque! El propio Arduino Uno tiene una capacidad de memoria del 75% con el código que has pegado.

Hay algunas maneras de solucionarlo. El primero sería el Programa anterior, para agregar estos arreglos de solo lectura a Flash y no a SRAM (o usar el espacio eeprom, esa es otra opción). En ese momento, debe estar por debajo del límite de SRAM de 0.5KB.

El segundo, que podría ser más fácil para ti comenzar, sería combinar cada uno de los 54 objetos en cada matriz, en grupos de 8. Ya que cada carácter ocupa 8 bits de memoria, y estás perdiendo 7 bits solo por ¡usar un objeto que es igual a 0 o 1, también conocido como bit, combinarlos ahorraría 7 bits cada uno, ** para un uso total de 161 bytes! **

  

const char it [] = {'1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0 ',' 0 ',' 0 ',' 0 ',' 0 ',' 0 ',' 0 ',' 0 ',' 0 ',' 0 ',' 0 ',' 0 ',' 0 ', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0 ',' 0 ',' 0 ',' 0 ',' 0 ',' 0 ',' 0 '};

Se convierte

  

const char it [] = {B10000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000,};

Esto agrega dos bits de almohadilla al final, aún ahorrando mucha memoria. Usé la notación binaria (B seguida por 8 bits), pero se puede usar hexadecimal o decimal. El editPins cambia a dos para bucles incrustados:

void editPins(const char add[]) {
  for (int a = 0; a < 7; a++) {
     for (int b = 0; b < 8; b++) {
      if ( (add[a] >> b) & 0x01 == 1) { //(if add[a] bit shifted and 1 equals 1)
         pins[((a + 1) * (b + 1)) - 1] = '1';
      }
     }
   }
 }

Mi sintaxis puede estar desactivada, pero los bucles recursivos están bien.

Y la tercera opción, sería una matriz de variables no demasiado complicada para un bucle for. Sus matrices son muy claras, ya que tienen todos los bits establecidos en 1 juntos, rodeados por 0 bits. Tendría una matriz que va:

  

ejemplo char [3] = {'número de ceros', 'número de unos', 'número de ceros'}

seguido de un conjunto de bucles for:

 //set i zeros
 for (int i = 0; i < example[0]; i++) pins[i] = 0;
 //set i ones
 for (int i = example[0]; i < example[1]; i++) pins[i] = 1;
 //set i zeros
 for (int i = example[1]; i < example[2]; i++) pins[i] = 0;

O la matriz tendría el índice de inicio de los 1 bits y la cantidad de 1 bits. La primera opción utiliza 3 bytes para cada matriz ( 69 bytes para las 23 matrices ), mientras que la última utiliza 2 bytes ( 46 bytes en total )

    
respondido por el Passerby
0

Desde la parte superior de mi cabeza, no conozco los detalles específicos del Uno (ATMega328p) y el ATtiny85, aparte de que este último tiene una fracción de la memoria y el espacio de código del primero.

Lo bueno es que estás usando const. Esa palabra clave coloca sus matrices de caracteres de caracteres que no cambian, en campos estáticos. En lugar de ponerlo en el ram, se coloca en el espacio del código. El espacio de código tiende a ser mucho más grande que el ram / memory. Muy eficiente.

Lo malo es que muchas declaraciones IF no son eficientes. Dependiendo de sus declaraciones, podría condensarlas en declaraciones de Caso / Cambio en su lugar. O condensar aún más con otros trucos de casos / interruptores.

Lo más probable es que la diferencia en el espacio del ram y del código esté causando errores de optimización. Algunas declaraciones o bucles podrían optimizarse para que quepan en el microcontrolador.

¿Es la razón por la que quiere un costo de ATTIN o tamaño físico? Debido a que un arduino Bare Bones en un ATMega328p en blanco es barato, y siempre puede obtener una versión de tamaño smd si el tamaño es una preocupación.

    
respondido por el Passerby

Lea otras preguntas en las etiquetas