In other post, a user suggest that doing this:
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] =
{
...
}
byte rowPins[ROWS] = { 22, 23, 24, 25 };
byte colPins[COLS] = {26, 27, 28, 29};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
wastes data memory space, and so, is better do:
char keys[4][4] =
{
...
}
byte rowPins[4] = { 22, 23, 24, 25 };
byte colPins[4] = {26, 27, 28, 29};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, 4, 4 );
He suggest too, to use this:
int freeRam () {
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
(...)
Serial.println(freeRam());
to test the free data space in RAM.
I did an "experiment", and I wrote this code:
int freeRam () {
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
void setup() {
Serial.begin(115200);
Serial.println(freeRam());
}
void loop() {}
And he return:
7994
for my MEGA.
I change it for:
const int variable = 5;
const int other = 3;
const char constChar = 124;
const char otherChar = 7;
int freeRam () {
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
void setup() {
Serial.begin(115200);
Serial.println(freeRam());
}
void loop() {}
And he return me the same value: 7994
.
I change it one more time to:
const int variable = 5;
const int other = 3;
const char constChar = 124;
const char otherChar = 7;
int a;
int b;
int freeRam () {
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
void setup() {
a = variable;
b = other;
Serial.begin(115200);
Serial.println(freeRam());
Serial.println();
Serial.println(a);
Serial.println(b);
}
void loop() {
}
And he return me:
7990
5
3
Less 4 bytes from the 2 int
global variables.
So, my conclusion is that the variables const int
are not placed in the the data space memory.
Is my conclusion right?