Creating a button list for microblocks micro:bit display

@Peter and @ewpatton
This is an attempt to create an app that sets the bits in the micro:bit display dynamically and to also make a list of buttons in a better way than creating the list by hand.
image image
The code to create the list:


The list is made from the anyblock every Button, first the connect button etc. are excluded, then the rest is sorted.
What I do not like about this solution that it is necessary to look at the text of the buttons. It is more work to set it that to create the list by hand. Once you have set the list you could delete the text on the buttons if you wish. Whould it not be nice if there would be a way to refer to the button names?
I attach the .aia and also the .ubp for the microblocks. Somehow it only works sometimes. I will look into this further, but I am rather stuck with microblocks side of it.
MicrobitMatrix20250214.aia (214.0 KB)
MacobitMatrix20250214.txt (4.8 KB)
(rename .txt to .ubp)

2 Likes

@Ghica Try to use this Extension. I already tested it and works well. It generates a List of the components created in the Designer, which can even use 'Wildcards' in these names, so that the Extension decides which components will consider to generate the List »

Get All Components using blocks - GetLabelComponentsByName

:pray:

Lito

@>-->---

1 Like

Thanks for appreciation

1 Like

Sometimes I just make a buttonlist. That is easy and I can do a lot of things with it, but such a long list doesn't look that good. I can use the index, etc. Sometimes I use the button text because I just have to send the value/string of the button to the microcontroller.

I am also trying to make something that can be done by young children during CoderDojo, so no "difficult" formula's but easy to explain. That is why on my MicroBlocks side I only have 5 blocks to display the result that is coming from the App Inventor app.

I rather not use to many extra extensions when doing this. I already have the BLE, MicroBlocks and Tools extension from @Taifun. I use the Tools extension to keep the screen active while being connected to the microcontroller.

It would be great if the MicroBlocks extension would be a part of the standard components. At the moment this is already available in the iOS companion and working.

@Peter Yes, making a list is easier to understand for kids, but this was about finding a more elegant and extensible solution.
@Lito I do not see the advantage of using your extension, because the anyBlocks everyButton block does already do what the extension seems to do: give you a list of all buttons in the designer. Or labels or whatever other component you can find in the anyBlocks.

in this particular case, we can make it more simple by change the filter block by check if the buttons' text is number, no need to make a separate buttonnames list.

I am not sure about this. There are the numbered buttons that indicate the position of the button in the matrix and there are buttons with text, such as “connect”. Everybutton returns the buttons in some random order, therefore you need to sort them because if you press the button you want to know its index in the list to know its location in the matrix. And you need to remove the not numeric buttons from the list.

i mean like this

1 Like

This is indeed more elegant, but it is a bit more work in the editor. In the end I have 12 blocks less in the total project, then when I used a long list of buttons.

I learned something new today :grin:

The MicroBlocks side still needs only 5 blocks to work and process the message send from the App Inventor project.

1 Like

Yes, you are right.

I estimate that you did not understand the proposed solution...

The suggested Extension can create Lists of existing Components, based on 'Wildcards' present in the Component names defined in the Designer, without the need to use later any filter that distinguishes them.

So if I want to have 3 separate Lists, one with the Labels, the other with the TextBoxs and the other with the Buttons, just add small Wildcards to the names of each in the Designer, that this will be sufficient for the Extension to know which components should consider to create each list.

In this example the Wildcards Lb, Tb & Bt were created as prefix. When calling the Extension it will only be necessary to inform these exclusive Wildcards of each Component to keep Lists separate:


Following the same reasoning, if you add some prefixes or suffixs to your Buttons names into the Designer, you can differentiate separate Lists to the Buttons containing text and for Buttons containing numbers, using some Wildcards »for example Txt for text and Nbr for numbers »

image

When doing this, it will be enough to inform these Wildcards in the Substring field when creating the Lists in the Editor »

And you will have a separate List for the Buttons containing text and a separate List for the Buttons containing numbers without having made a single comparison and without applying any programmatic filter.

With these separate Lists you will already know how to deal with them and apply the specific procedures for each.


That was the most elegant solution I found... If there is any more elegant than this, please let me know.

:pray:

Lito

@>-->---

Great. I think you could add this example of application to your Extension documentation (as a link)

:pray:

Lito

@>-->---

1 Like

Thanks was going to do it without reading the second post.
You described the extension in such an elegant manner

1 Like

Yeah, but how do I get the number buttons sorted by button name in the resulting list?

I estimate that the order on the List is generated from the order of creation of the Component in the Designer... so the Button that was created first will come first, the second will be the second... but I'm not sure about it. Until I can do some tests is better that you do the test first, paying close attention to the order of creation of each Component in the Designer. Still, if this is not true, there are ways to circumvent this issue. Do not forget that there is a way to use the Wildcards along with the Add Items to List Block... and that this can be done inside a loop »

image

:pray:

Lito

@>-->---

So far, it seems that the solution I posted is best, with a small modification by @Kevinkun. I do not see any advantage in using the extension, because you still need to sort the buttons.
There may be cases where there is an advantage to know the component name, but not here.

With extension CompCreator, you can get a list of buttons in order, no need to sort them again.

1 Like