 # optimization

hello

I have a display max7219 my code looks like its

``````Write_Max7219 (1, B00000000);
Write_Max7219 (2, B00000000);
Write_Max7219 (3, B00000000);
Write_Max7219 (4, B00000000);
Write_Max7219 (5, B00000000);
Write_Max7219 (6, B00000000);
Write_Max7219 (7, B00000000);
Write_Max7219 (8, B00000000);
``````

I do not know if it is clear what I want to do my roughly be able to optimize the first code by something more compact like its return
often
is it possible to modify it in this style

``````for (int i =1; i <=9; i++{
Write_Max7219(i, B00000000);
}
``````

yes. the loop is a good idea. values can be computed from the loop index. You save code space for each function call.

but if the values were unique, you could create a table of structures where each table entry is integer and binary value and you loop thru the table pulling values.

ludocraft:
hello

I have a display max7219 my code looks like its

``````Write_Max7219 (1, B00000000);
``````

Write_Max7219 (2, B00000000);
Write_Max7219 (3, B00000000);
Write_Max7219 (4, B00000000);
Write_Max7219 (5, B00000000);
Write_Max7219 (6, B00000000);
Write_Max7219 (7, B00000000);
Write_Max7219 (8, B00000000);

``````

I do not know if it is clear what I want to do my roughly be able to optimize the first code by something more compact like its return
often
is it possible to modify it in this style

``````

for (int i =1; i <=9; i++{
Write_Max7219(i, B00000000);
}

Those pieces of code are not equivalent. The for loop goes from 1…9 but your original code goes from 1…8.
Also, B00000000 is the binary representation of 0 so why not just use that?

``````for (int i =1; i <9; i++{
Write_Max7219(i, 0);
}
``````

i forgot to say my i9 serve me for something else after thanks to both of you will help me save :)