(Due to the limited memory available on most Arduino boards, I sometimes run into problems using valid C / C ++ code, so this question specifically concerns any problems with using Arduino structures.)
I saw an example of code for using structures in Arduino , but does not discuss memory issues.
- Is the size of the structure just the sum of the data types of its fields?
- Is saving structures in PROGMEM an option? Are there any problems with access speed?
- Are the structure fields writable (for example, the example below
s1.LED1.state = 0; ) (although not saved in PROGMEM, of course). - Is it possible to define the structure field as a structure of another type (of another type)?
- Is it possible to iterate through a structure to use
for..in or by index?
My use case is that I have 64 LEDs controlled by a MAX7219 chip. Due to the requirements of the physical wiring layout, it would be more convenient to arrange the order of the LEDs in a more logical way using structures in order to simplify / more harmonize programming.
typedef struct { byte row : 6; byte col : 128; byte state : 1; } LED;
typedef struct { LED LED1 : {1,1,1}; LED LED2 : {1,2,1}; LED LED3 : {1,4,1}; LED LED4 : {1,8,1}; LED LED5 : {1,16,1}; LED LED6 : {1,32,1}; LED LED7 : {1,64,1}; LED LED8 : {1,128,1}; } LED_SECTION;
LED_SECTION s1; s1.LED1.row = 1;
s1.LED1.state = 0;
No grabbing
source share