How do I simplify a long function?

Good morning all !
I'm looking for a solution to simplify this ...
I know you will laugh !!!
Have a good day!

for (int i = jd; i <= jf; i++) {
sommef = sommef + (at24.read(i));
sommev = sommev + (at24.read(i + 10000));
Serial1.print("j" + String(j) + "|" + String(at24.read(i)) + "|" + String(at24.read(i + 10000)) + "|" + String(sommef) + "|" + String(sommev));
j++ ;
delay(50);
}

Does your decision to stop counting at 31 mean that each row of your table represents readings for a day in a month?

If so, export your .aia file and post it here, to make it easier to work up a simplification using lists of components and generic blocks.

Good evening ABG,
Indeed, it is a question of reading data of a month sent by arduino.
I failed to create a procedure to avoid having 31 blocks.
Display_data_from_arduino.aia (214.6 KB)

1 Like

Hmmm... the length reminds me of some of my projects.... @ABG remembers the horrors.

Posts with huge blocks

How do I set an open listpicker to another list? (Newb mistakes?)

Any advice as how to make these blocks not as big?

@Slegg Have you tried procedures with parameters? That helped me in both of those posts.

I've added the .aia here ↓ as an example of procedures with parameters...
Unstoppable.aia (56.1 KB)

Hi netminderno !
I feel less alone thanks to you !!!!
I do not see how to do with the settings.
I think with a loop "for each items" it is possible but I am new and I am learning ...

1 Like

Here is my first level simplification.
(I did not deal with the global buffer variable that grows infinitely, nor
with the table arrangement that is buggy (AI2's fault)
nor with the lack of a place where you clear the table, nor with
your trying to re-invent month names and their relation to month lengths).
Display_data_from_arduino_ABG.aia (195.3 KB)

Typeblocking and a numeric keypad made this easier than it should have been.

Parallel ListViews would have made this even easier.

P.S. All block images are draggable directly from here into the Blocks Editor.

2 Likes

ABG ...
it works perfectly.
Thank you, thank you and thank you!
What do you mean by: the global buffer variable which grows ad infinitum?

1 Like

@Slegg I think a very complex loop would work, but @ABG figured out a sort of workaround before I even got to figure it out.

https://community.appinventor.mit.edu/u/netminderno.9apps, :slight_smile: :slight_smile: It's very generous at ABG to offer all this rich information that works !!!!!
I am learning and what he sent me is precious for me to grow!

1 Like

ad infinitum means to infinity.
8d3a2f65a5980060c9eb22885b3a0f91b30fd554_2_690x246

ad infinitum means to infinity! OK for me ! So agree with you!
Maybe I need to clear the buffer right after receiving data?
I don't know how to do this.
As I said to Profile - netminderno.9apps - MIT App Inventor Community, I am learning.
so I'm trying to figure out what you sent me.
Question: where did you find "set Label" ???

blocks-5

Those blocks are found by expanding the "Any Component" section of the blocks selector list and then selecting "Any Label".

1 Like

This is very valuable information!
Christmas is not over then?
There is a lot of benevolence on App Inventor! it feels good.
Thank you ewpatton.

1 Like

ABG,
Do you agree with my suggestion of clearing buffering?

Aside from noticing that join "" is equivalent to "", I haven't seen any place
in your blocks where you actually use the global variable inputBuffer, except to build it up.

So why do you keep something you don't use?


Hello ABG,
But yes of course! it is absolutely unnecessary!
I tried so many combinations that I forgot to clean up and simplify.
Thank you very much ABG.
you are my teacher!
Have a good day

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.