I'm trying to make my Arduino Uno control the air conditioner by recording the raw IR signal of several of the AC remotes temperatures using AnalysisIR. However these IR codes are quite long (array with 343 items).
Declaring more than one IR code in a variable shows me the error: "Global variables use 2064 bytes (100%) of dynamic memory, leaving -16 bytes for local variables. Maximum is 2048 bytes."
However, as seen in my code, I have declared the IR codes locally in a separate function to send them to the air conditioner. I don't understand why i get the error saying the global variables are taking up too much dynamic memory.
Isn't the space taken up by the local variable supposed to be freed up from the SRAM once the functions runs because I have declared the variable locally?
Thanks in advance.
Code:
#include <IRremote.h>
IRsend irsend;
int khz = 38;
void send23()
{
unsigned int irSignal[]= {9048, 4496, 620, 1636, 620, 1636, 620, 520, 620, 520, 620, 524, 624, 524, 620, 532, 620, 1648, 620, 508, 620, 1640, 620, 1644, 620, 520, 620, 528, 616, 528, 620, 532, 624, 516, 620, 1636, 620, 516, 616, 520, 620, 520, 620, 524, 620, 528, 616, 536, 620, 520, 620, 508, 620, 1640, 620, 520, 620, 520, 620, 1648, 620, 1656, 620, 1656, 616, 524, 620, 508, 620, 516, 616, 520, 620, 520, 624, 520, 620, 528, 620, 532, 620, 520, 620, 508, 624, 508, 624, 516, 616, 520, 624, 524, 620, 524, 620, 532, 620, 504, 620, 7956, 616, 512, 620, 1640, 616, 520, 620, 520, 620, 524, 620, 528, 620, 528, 624, 1644, 620, 1636, 616, 1640, 624, 1640, 620, 1648, 616, 528, 620, 1652, 620, 532, 620, 520, 620, 512, 620, 512, 620, 516, 620, 524, 620, 524, 616, 528, 620, 532, 620, 520, 620, 508, 620, 512, 624, 512, 620, 520, 620, 520, 620, 528, 620, 532, 620, 520, 620, 508, 620, 516, 620, 516, 620, 520, 620, 524, 620, 524, 624, 528, 624, 516, 620, 508, 620, 512, 624, 512, 624, 516, 624, 520, 624, 524, 624, 528, 620, 520, 624, 504, 624, 512, 620, 516, 624, 516, 620, 524, 620, 524, 624, 528, 620, 520, 624, 504, 624, 1636, 624, 1640, 624, 1640, 624, 1648, 620, 524, 624, 1656, 624, 1624, 624, 7952, 616, 512, 624, 508, 624, 512, 624, 516, 624, 520, 624, 524, 624, 524, 624, 520, 624, 504, 624, 1636, 624, 512, 624, 516, 624, 520, 624, 524, 624, 524, 628, 516, 624, 504, 624, 508, 624, 512, 624, 516, 624, 520, 624, 524, 620, 528, 628, 512, 624, 508, 624, 508, 624, 512, 620, 520, 620, 524, 624, 520, 624, 528, 624, 516, 620, 508, 624, 508, 624, 512, 624, 1640, 624, 520, 624, 524, 624, 528, 624, 512, 628, 504, 624, 508, 624, 512, 624, 516, 624, 520, 624, 524, 624, 528, 624, 516, 620, 508, 624, 1632, 628, 508, 628, 1640, 624, 520, 624, 524, 620, 528, 624, 500, 608};
irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz); //Note the approach used to automatically calculate the size of the array.
}
void send22()
{
unsigned int irSignal[]= {8988, 4548, 572, 1688, 572, 1688, 600, 532, 572, 568, 572, 572, 576, 572, 572, 580, 572, 1724, 544, 556, 576, 1684, 600, 1660, 608, 532, 604, 540, 608, 540, 600, 548, 608, 536, 604, 1652, 608, 520, 616, 524, 608, 532, 612, 532, 612, 532, 620, 532, 616, 524, 620, 512, 616, 1644, 624, 508, 628, 516, 624, 520, 628, 1676, 596, 1648, 632, 508, 632, 500, 632, 500, 632, 504, 636, 504, 636, 512, 628, 516, 632, 524, 628, 508, 636, 496, 632, 504, 628, 508, 632, 508, 632, 512, 632, 516, 632, 516, 632, 496, 628, 7948, 628, 500, 632, 1656, 600, 508, 628, 508, 632, 512, 632, 516, 632, 524, 628, 1636, 632, 496, 632, 504, 632, 504, 632, 508, 632, 1672, 600, 1672, 600, 520, 632, 508, 632, 500, 652, 480, 632, 504, 632, 512, 628, 512, 632, 516, 632, 520, 632, 508, 632, 496, 632, 504, 632, 504, 632, 508, 632, 516, 628, 520, 628, 520, 656, 484, 632, 500, 656, 476, 656, 480, 632, 508, 632, 516, 632, 512, 656, 496, 632, 508, 632, 500, 652, 480, 632, 504, 656, 484, 656, 488, 632, 516, 632, 520, 632, 508, 632, 500, 656, 476, 632, 508, 656, 484, 656, 488, 656, 492, 632, 520, 656, 484, 656, 1632, 624, 476, 632, 508, 656, 484, 656, 1620, 652, 488, 656, 1656, 600, 1648, 604, 7948, 656, 472, 656, 476, 660, 480, 632, 508, 656, 488, 652, 496, 656, 492, 656, 484, 632, 500, 656, 1608, 628, 504, 656, 484, 656, 488, 656, 492, 656, 496, 656, 484, 632, 496, 656, 480, 632, 504, 656, 484, 656, 488, 632, 516, 656, 496, 628, 508, 660, 472, 656, 480, 656, 480, 652, 488, 656, 488, 656, 492, 652, 496, 660, 484, 656, 472, 632, 504, 652, 484, 652, 1644, 624, 488, 656, 492, 656, 492, 632, 512, 628, 500, 664, 468, 656, 480, 656, 488, 652, 488, 656, 492, 656, 492, 632, 512, 652, 476, 656, 1632, 624, 484, 652, 1644, 620, 492, 656, 488, 628, 524, 652, 472, 608};
irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz); //Note the approach used to automatically calculate the size of the array.
}
void setup()
{
Serial.begin(9600);
pinMode(13,OUTPUT);
delay(2000);
send23();
delay(2000);
send22();
}
void loop() {
}
EDIT 05/07:
Here is my new code with the use of PROGMEM.
As you can see, i have initialized the progmem arrays globally at the top of the program. When i do this, my SRAM is not full anymore but sendraw in the functions does not work anymore.
Weirdly however, when i declare the progmem variable INSIDE the send23() function (IN COMMENTS), the sendraw works! But the variable takes up space in the SRAM again and it says that Global variables have used 100% of dynamic memory.
Why does this happen and what can i do to work around it?
PROGMEM updated code:
#include <IRremote.h>
const unsigned int irSignal23[] PROGMEM = {9048, 4496, 620, 1636, 620, 1636, 620, 520, 620, 520, 620, 524, 624, 524, 620, 532, 620, 1648, 620, 508, 620, 1640, 620, 1644, 620, 520, 620, 528, 616, 528, 620, 532, 624, 516, 620, 1636, 620, 516, 616, 520, 620, 520, 620, 524, 620, 528, 616, 536, 620, 520, 620, 508, 620, 1640, 620, 520, 620, 520, 620, 1648, 620, 1656, 620, 1656, 616, 524, 620, 508, 620, 516, 616, 520, 620, 520, 624, 520, 620, 528, 620, 532, 620, 520, 620, 508, 624, 508, 624, 516, 616, 520, 624, 524, 620, 524, 620, 532, 620, 504, 620, 7956, 616, 512, 620, 1640, 616, 520, 620, 520, 620, 524, 620, 528, 620, 528, 624, 1644, 620, 1636, 616, 1640, 624, 1640, 620, 1648, 616, 528, 620, 1652, 620, 532, 620, 520, 620, 512, 620, 512, 620, 516, 620, 524, 620, 524, 616, 528, 620, 532, 620, 520, 620, 508, 620, 512, 624, 512, 620, 520, 620, 520, 620, 528, 620, 532, 620, 520, 620, 508, 620, 516, 620, 516, 620, 520, 620, 524, 620, 524, 624, 528, 624, 516, 620, 508, 620, 512, 624, 512, 624, 516, 624, 520, 624, 524, 624, 528, 620, 520, 624, 504, 624, 512, 620, 516, 624, 516, 620, 524, 620, 524, 624, 528, 620, 520, 624, 504, 624, 1636, 624, 1640, 624, 1640, 624, 1648, 620, 524, 624, 1656, 624, 1624, 624, 7952, 616, 512, 624, 508, 624, 512, 624, 516, 624, 520, 624, 524, 624, 524, 624, 520, 624, 504, 624, 1636, 624, 512, 624, 516, 624, 520, 624, 524, 624, 524, 628, 516, 624, 504, 624, 508, 624, 512, 624, 516, 624, 520, 624, 524, 620, 528, 628, 512, 624, 508, 624, 508, 624, 512, 620, 520, 620, 524, 624, 520, 624, 528, 624, 516, 620, 508, 624, 508, 624, 512, 624, 1640, 624, 520, 624, 524, 624, 528, 624, 512, 628, 504, 624, 508, 624, 512, 624, 516, 624, 520, 624, 524, 624, 528, 624, 516, 620, 508, 624, 1632, 628, 508, 628, 1640, 624, 520, 624, 524, 620, 528, 624, 500, 608};
const unsigned int irSignal22[] PROGMEM = {8988, 4548, 572, 1688, 572, 1688, 600, 532, 572, 568, 572, 572, 576, 572, 572, 580, 572, 1724, 544, 556, 576, 1684, 600, 1660, 608, 532, 604, 540, 608, 540, 600, 548, 608, 536, 604, 1652, 608, 520, 616, 524, 608, 532, 612, 532, 612, 532, 620, 532, 616, 524, 620, 512, 616, 1644, 624, 508, 628, 516, 624, 520, 628, 1676, 596, 1648, 632, 508, 632, 500, 632, 500, 632, 504, 636, 504, 636, 512, 628, 516, 632, 524, 628, 508, 636, 496, 632, 504, 628, 508, 632, 508, 632, 512, 632, 516, 632, 516, 632, 496, 628, 7948, 628, 500, 632, 1656, 600, 508, 628, 508, 632, 512, 632, 516, 632, 524, 628, 1636, 632, 496, 632, 504, 632, 504, 632, 508, 632, 1672, 600, 1672, 600, 520, 632, 508, 632, 500, 652, 480, 632, 504, 632, 512, 628, 512, 632, 516, 632, 520, 632, 508, 632, 496, 632, 504, 632, 504, 632, 508, 632, 516, 628, 520, 628, 520, 656, 484, 632, 500, 656, 476, 656, 480, 632, 508, 632, 516, 632, 512, 656, 496, 632, 508, 632, 500, 652, 480, 632, 504, 656, 484, 656, 488, 632, 516, 632, 520, 632, 508, 632, 500, 656, 476, 632, 508, 656, 484, 656, 488, 656, 492, 632, 520, 656, 484, 656, 1632, 624, 476, 632, 508, 656, 484, 656, 1620, 652, 488, 656, 1656, 600, 1648, 604, 7948, 656, 472, 656, 476, 660, 480, 632, 508, 656, 488, 652, 496, 656, 492, 656, 484, 632, 500, 656, 1608, 628, 504, 656, 484, 656, 488, 656, 492, 656, 496, 656, 484, 632, 496, 656, 480, 632, 504, 656, 484, 656, 488, 632, 516, 656, 496, 628, 508, 660, 472, 656, 480, 656, 480, 652, 488, 656, 488, 656, 492, 652, 496, 660, 484, 656, 472, 632, 504, 652, 484, 652, 1644, 624, 488, 656, 492, 656, 492, 632, 512, 628, 500, 664, 468, 656, 480, 656, 488, 652, 488, 656, 492, 656, 492, 632, 512, 652, 476, 656, 1632, 624, 484, 652, 1644, 620, 492, 656, 488, 628, 524, 652, 472, 608};
const unsigned int irSignal21[] PROGMEM = {9044, 4496, 624, 1628, 628, 1592, 668, 508, 628, 512, 628, 516, 628, 520, 628, 524, 628, 1636, 632, 500, 628, 1632, 624, 1636, 628, 512, 628, 520, 628, 516, 628, 524, 628, 512, 628, 1628, 628, 512, 620, 512, 624, 516, 628, 516, 628, 520, 628, 524, 628, 512, 628, 500, 632, 1628, 628, 512, 628, 512, 628, 1644, 628, 520, 628, 1648, 628, 512, 628, 504, 624, 508, 628, 508, 632, 508, 628, 516, 632, 516, 628, 524, 628, 512, 628, 504, 628, 504, 628, 508, 628, 512, 628, 516, 628, 520, 628, 524, 624, 500, 624, 7948, 628, 504, 628, 1628, 628, 512, 624, 516, 624, 516, 628, 520, 628, 524, 628, 1636, 628, 504, 624, 1632, 628, 508, 628, 512, 628, 1640, 628, 1648, 628, 520, 628, 512, 628, 504, 628, 504, 628, 508, 628, 512, 628, 516, 628, 516, 628, 524, 628, 512, 628, 500, 628, 504, 628, 508, 628, 512, 628, 516, 628, 520, 628, 520, 628, 512, 628, 500, 632, 504, 628, 508, 628, 512, 624, 520, 624, 520, 628, 524, 624, 516, 624, 504, 628, 504, 628, 508, 628, 512, 628, 516, 628, 520, 628, 520, 628, 512, 628, 504, 628, 504, 628, 508, 624, 516, 628, 512, 628, 520, 628, 524, 624, 516, 628, 1624, 628, 1632, 628, 508, 628, 512, 628, 516, 628, 1644, 628, 1648, 628, 1620, 628, 7944, 628, 500, 628, 504, 628, 512, 624, 512, 628, 516, 628, 520, 628, 520, 628, 512, 628, 504, 624, 1636, 624, 508, 632, 508, 628, 516, 628, 520, 628, 520, 632, 512, 624, 504, 628, 504, 628, 508, 628, 512, 628, 516, 628, 520, 628, 524, 624, 516, 628, 500, 628, 504, 628, 508, 628, 512, 628, 516, 628, 520, 628, 524, 624, 512, 628, 504, 624, 508, 628, 508, 628, 1640, 624, 516, 628, 520, 628, 524, 624, 516, 624, 504, 628, 504, 628, 508, 628, 512, 628, 516, 628, 520, 628, 524, 624, 512, 628, 504, 628, 1632, 624, 512, 628, 1640, 624, 516, 628, 520, 628, 524, 628, 492, 612};
IRsend irsend;
int khz = 38;
void send23()
{
// const unsigned int irSignal23[] PROGMEM = {9048, 4496, 620, 1636, 620, 1636, 620, 520, 620, 520, 620, 524, 624, 524, 620, 532, 620, 1648, 620, 508, 620, 1640, 620, 1644, 620, 520, 620, 528, 616, 528, 620, 532, 624, 516, 620, 1636, 620, 516, 616, 520, 620, 520, 620, 524, 620, 528, 616, 536, 620, 520, 620, 508, 620, 1640, 620, 520, 620, 520, 620, 1648, 620, 1656, 620, 1656, 616, 524, 620, 508, 620, 516, 616, 520, 620, 520, 624, 520, 620, 528, 620, 532, 620, 520, 620, 508, 624, 508, 624, 516, 616, 520, 624, 524, 620, 524, 620, 532, 620, 504, 620, 7956, 616, 512, 620, 1640, 616, 520, 620, 520, 620, 524, 620, 528, 620, 528, 624, 1644, 620, 1636, 616, 1640, 624, 1640, 620, 1648, 616, 528, 620, 1652, 620, 532, 620, 520, 620, 512, 620, 512, 620, 516, 620, 524, 620, 524, 616, 528, 620, 532, 620, 520, 620, 508, 620, 512, 624, 512, 620, 520, 620, 520, 620, 528, 620, 532, 620, 520, 620, 508, 620, 516, 620, 516, 620, 520, 620, 524, 620, 524, 624, 528, 624, 516, 620, 508, 620, 512, 624, 512, 624, 516, 624, 520, 624, 524, 624, 528, 620, 520, 624, 504, 624, 512, 620, 516, 624, 516, 620, 524, 620, 524, 624, 528, 620, 520, 624, 504, 624, 1636, 624, 1640, 624, 1640, 624, 1648, 620, 524, 624, 1656, 624, 1624, 624, 7952, 616, 512, 624, 508, 624, 512, 624, 516, 624, 520, 624, 524, 624, 524, 624, 520, 624, 504, 624, 1636, 624, 512, 624, 516, 624, 520, 624, 524, 624, 524, 628, 516, 624, 504, 624, 508, 624, 512, 624, 516, 624, 520, 624, 524, 620, 528, 628, 512, 624, 508, 624, 508, 624, 512, 620, 520, 620, 524, 624, 520, 624, 528, 624, 516, 620, 508, 624, 508, 624, 512, 624, 1640, 624, 520, 624, 524, 624, 528, 624, 512, 628, 504, 624, 508, 624, 512, 624, 516, 624, 520, 624, 524, 624, 528, 624, 516, 620, 508, 624, 1632, 628, 508, 628, 1640, 624, 520, 624, 524, 620, 528, 624, 500, 608};
irsend.sendRaw(irSignal23, sizeof(irSignal23) / sizeof(irSignal23[0]), khz); //Note the approach used to automatically calculate the size of the array.
}
void send22()
{
// const unsigned int irSignal22[] PROGMEM = {8988, 4548, 572, 1688, 572, 1688, 600, 532, 572, 568, 572, 572, 576, 572, 572, 580, 572, 1724, 544, 556, 576, 1684, 600, 1660, 608, 532, 604, 540, 608, 540, 600, 548, 608, 536, 604, 1652, 608, 520, 616, 524, 608, 532, 612, 532, 612, 532, 620, 532, 616, 524, 620, 512, 616, 1644, 624, 508, 628, 516, 624, 520, 628, 1676, 596, 1648, 632, 508, 632, 500, 632, 500, 632, 504, 636, 504, 636, 512, 628, 516, 632, 524, 628, 508, 636, 496, 632, 504, 628, 508, 632, 508, 632, 512, 632, 516, 632, 516, 632, 496, 628, 7948, 628, 500, 632, 1656, 600, 508, 628, 508, 632, 512, 632, 516, 632, 524, 628, 1636, 632, 496, 632, 504, 632, 504, 632, 508, 632, 1672, 600, 1672, 600, 520, 632, 508, 632, 500, 652, 480, 632, 504, 632, 512, 628, 512, 632, 516, 632, 520, 632, 508, 632, 496, 632, 504, 632, 504, 632, 508, 632, 516, 628, 520, 628, 520, 656, 484, 632, 500, 656, 476, 656, 480, 632, 508, 632, 516, 632, 512, 656, 496, 632, 508, 632, 500, 652, 480, 632, 504, 656, 484, 656, 488, 632, 516, 632, 520, 632, 508, 632, 500, 656, 476, 632, 508, 656, 484, 656, 488, 656, 492, 632, 520, 656, 484, 656, 1632, 624, 476, 632, 508, 656, 484, 656, 1620, 652, 488, 656, 1656, 600, 1648, 604, 7948, 656, 472, 656, 476, 660, 480, 632, 508, 656, 488, 652, 496, 656, 492, 656, 484, 632, 500, 656, 1608, 628, 504, 656, 484, 656, 488, 656, 492, 656, 496, 656, 484, 632, 496, 656, 480, 632, 504, 656, 484, 656, 488, 632, 516, 656, 496, 628, 508, 660, 472, 656, 480, 656, 480, 652, 488, 656, 488, 656, 492, 652, 496, 660, 484, 656, 472, 632, 504, 652, 484, 652, 1644, 624, 488, 656, 492, 656, 492, 632, 512, 628, 500, 664, 468, 656, 480, 656, 488, 652, 488, 656, 492, 656, 492, 632, 512, 652, 476, 656, 1632, 624, 484, 652, 1644, 620, 492, 656, 488, 628, 524, 652, 472, 608};
irsend.sendRaw(irSignal22, sizeof(irSignal22) / sizeof(irSignal22[0]), khz); //Note the approach used to automatically calculate the size of the array.
}
void send21()
{
// const unsigned int irSignal21[] PROGMEM = {9044, 4496, 624, 1628, 628, 1592, 668, 508, 628, 512, 628, 516, 628, 520, 628, 524, 628, 1636, 632, 500, 628, 1632, 624, 1636, 628, 512, 628, 520, 628, 516, 628, 524, 628, 512, 628, 1628, 628, 512, 620, 512, 624, 516, 628, 516, 628, 520, 628, 524, 628, 512, 628, 500, 632, 1628, 628, 512, 628, 512, 628, 1644, 628, 520, 628, 1648, 628, 512, 628, 504, 624, 508, 628, 508, 632, 508, 628, 516, 632, 516, 628, 524, 628, 512, 628, 504, 628, 504, 628, 508, 628, 512, 628, 516, 628, 520, 628, 524, 624, 500, 624, 7948, 628, 504, 628, 1628, 628, 512, 624, 516, 624, 516, 628, 520, 628, 524, 628, 1636, 628, 504, 624, 1632, 628, 508, 628, 512, 628, 1640, 628, 1648, 628, 520, 628, 512, 628, 504, 628, 504, 628, 508, 628, 512, 628, 516, 628, 516, 628, 524, 628, 512, 628, 500, 628, 504, 628, 508, 628, 512, 628, 516, 628, 520, 628, 520, 628, 512, 628, 500, 632, 504, 628, 508, 628, 512, 624, 520, 624, 520, 628, 524, 624, 516, 624, 504, 628, 504, 628, 508, 628, 512, 628, 516, 628, 520, 628, 520, 628, 512, 628, 504, 628, 504, 628, 508, 624, 516, 628, 512, 628, 520, 628, 524, 624, 516, 628, 1624, 628, 1632, 628, 508, 628, 512, 628, 516, 628, 1644, 628, 1648, 628, 1620, 628, 7944, 628, 500, 628, 504, 628, 512, 624, 512, 628, 516, 628, 520, 628, 520, 628, 512, 628, 504, 624, 1636, 624, 508, 632, 508, 628, 516, 628, 520, 628, 520, 632, 512, 624, 504, 628, 504, 628, 508, 628, 512, 628, 516, 628, 520, 628, 524, 624, 516, 628, 500, 628, 504, 628, 508, 628, 512, 628, 516, 628, 520, 628, 524, 624, 512, 628, 504, 624, 508, 628, 508, 628, 1640, 624, 516, 628, 520, 628, 524, 624, 516, 624, 504, 628, 504, 628, 508, 628, 512, 628, 516, 628, 520, 628, 524, 624, 512, 628, 504, 628, 1632, 624, 512, 628, 1640, 624, 516, 628, 520, 628, 524, 628, 492, 612};
irsend.sendRaw(irSignal21, sizeof(irSignal21) / sizeof(irSignal21[0]), khz); //Note the approach used to automatically calculate the size of the array.
}
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
send23();
Serial.println("done");
delay(4000);
send22();
Serial.println("done");
delay(4000);
send21();
Serial.println("done");
}
void loop() {
}