I have an array of a lot of numbers (1 and 0) but i can't store them since arduino does not have enough space. How can i save an array of example 00110 in PROGMEM, then read from PROGMEM and set x to be equal lets say, third int in the array?
Store them with Use the following macro to retrieve them (untested):
So if you had Naturally if you needed more than one bit at a time there are probably situation-specific routines that could be used, but without knowing anything about the actual program the above will work. |
|||
As noted in Ignacio's answer, you can pack your bits of data into bytes and access them via Here's an example program that accesses and prints data from program memory in 16-bit chunks:
To pack your 4000 bits of data in the first place, write a C or Python program that runs on a host computer and writes out array definitions that you can cut and paste into a sketch. Here's an example (in Python) that packs bits into bytes:
Here is what the program produces:
If you want that code to instead pack bits into 16-bit words, change 8 to 16 in four places. Note, the code stores bits in the “bit 0 as MSb and bit 7 as LSb” order mentioned in Ignacio's answer. Thus, |
|||||||||||||||||
|
Building on the excellent other answers by jwpat7 and Ignacio Vazquez-Abrams, you could conceivably convert your bits into a table using Lua:
Output from above:
Now you can make a simple function to pull a particular bit out of PROGMEM:
Output from above:
|
|||
|
int
variables (as you seem to suggest) that's a massive 8KB. Packed into individual bits of a byte that's a mere 500 bytes. – Majenko Sep 11 at 20:25