Random function and Bluetooth

Hello everyone.The idea is that if a button is pressed, then the application should randomly select (1,2,3,4,5,6,7,8,9). If you chose 5, then it also has (a, b, v, g, d) and bluetooth should send in turn and in order every 1 seconds, and when it ends randomly, the function should select again, and so on

I'm new to this and the blocks are not at all correct please help

Use the math block "random integor for 1 to 5" to select a random number. Save the number to a variable, e.g. "number". Use the list to store the values you will send via bt. In the clock component, use the variable index that you will increment every time the clock passes. Then send via bt the value from the list (here use conditional blocks "if", variable "number" = 1, use list 1 "else if" variable "number" = 2, use list 2 etc ...) variable with index from variable "index", as long as the variable index is less than or equal to the length of the selected list of values.

thank you very much, but can you show it on the block please

Analyze what I wrote and bring some of your work, don't just count on the finished product.
Then show what you have achieved, write whether it works or not. Then I will help you further ...

Did I understand you correctly? but did not understand what to do with random

Use only one random variable. For example, initialize it with the number 1. In the button1.click block, write a random number from the block "random integer for 1 to 5" to this variable. You will then have a random number stored in this variable. I understand that a random number from 1 to 5 corresponds to different sets of variables sent by BT? For example, 1 is a, b, v, d, e, but 2 will be different data, e.g. b, c, x, e, d? If so, you need to create lists for all data combinations with the "make a list" block.

yes you understood me correctly

make a list of only one or enough for each separately and where to connect it

It will show it faster in blocks:

blocks - 2021-05-22T105707.461

1 Like

thanks a lot, it works. But sorry, I forgot to say something, I need to send 3 characters instead of one, I changed everything from 1 to 3, but the application sends 2 and ignores the rest, if the list contains (abc, acb, adb, agb), then the application sends only abc and adb

Don't change anything from 1 to 3 because the app will stop working. You can send any text length without any changes.

Don't take screenshots as you can't see anything in your images after inserting here. Ai2 has the function of saving blocks to a png file. Right-click on an empty workspace, and select "download blocks as image" from the context menu.

Thanks a lot for the info, can now start the Clock when this is over
for example, now I changed the button to switch and when clock finishes its work it should start again and so on

in this case, the random function does not work, it sends the same text over and over again

and in this case it does not send correctly

blocks - 2021-05-22T131644.898 blocks - 2021-05-22T131628.207

1 Like

thank you so much it worked

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