The smaller Arduinos like the Arduino Uno have 2k of RAM. The subs stack and the global variables use this memory.
If your program includes constant data then you can use PROGMEM to store the data in the program code and access it without loading the whole data into the the limited RAM.
Complete example:
1. Update the data array with your own data.
2. Use GetByte to read from the stored data.
If your program includes constant data then you can use PROGMEM to store the data in the program code and access it without loading the whole data into the the limited RAM.
Complete example:
B4X:
Sub Process_Globals
Public Serial1 As Serial
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
Log("RAM: ", AvailableRAM)
For i = 0 To 20
Log(GetByte(i))
Next
End Sub
Private Sub GetByte(Index As UInt) As Byte
Return RunNative("getdata", Index)
End Sub
#if C
#include <avr/pgmspace.h>
const PROGMEM byte data[] = { //change the data here
1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 0xFF, 0xFE,
8, 9, 10, 11, 0xFF, 0xFE,
8, 9, 10, 11, 0xFF, 0xFE,
8, 9, 10, 11, 0xFF, 0xFE,
8, 9, 10, 11, 0xFF, 0xFE,
8, 9, 10, 11, 0xFF, 0xFE,
8, 9, 10, 11, 0xFF, 0xFE,
8, 9, 10, 11, 0xFF, 0xFE
};
B4R::Object beo1;
B4R::Object* getdata(B4R::Object* o) {
return beo1.wrapNumber(pgm_read_byte_near(data + o->toLong()));
}
#end if
1. Update the data array with your own data.
2. Use GetByte to read from the stored data.