Jump to content

Bliss

Eurobricks Citizen
  • Posts

    165
  • Joined

  • Last visited

1 Follower

About Bliss

Spam Prevention

  • What is favorite LEGO theme? (we need this info to prevent spam)
    Technic
  • Which LEGO set did you recently purchase or build?
    None for now

Profile Information

  • Gender
    Male
  • Location
    Canada

Extra

  • Country
    Canada

Recent Profile Visitors

1,218 profile views
  1. The Tasks Category has been added. I did not test everything but the basic works. I will add few more things... The Functions are now synchronized so avoid using forever loops into them. Version: 2026-03-31-0311 The following example works for me. In the main loop, I could have used in theory just the start task block without the "if block" because it's not supposed to start multiple instance. EDIT: Notice the new blocks loop forever and task loop that both integrates a "repeat while true" along with a "Yield" (Similar to Wait 0.001s but the smallest time possible not to hang the page) The Loop forever is in the Control Category. There is a also a block "Yield" you can use in a repeat while true in replacement to wait ## sec. The Task category has a Task Loop definition and also a Task definition without integrated loop + yield. Also the task category includes a sleep that is better than a wait inside a task (it's non blocking)... The diffirence between sleep time and wait time is a bit confusing for me, but Copilot told me it is better... :-)
  2. @Toastie, I made some tests and found out that the Blockly Functions were actually asynchronous since I'm using an Async approach to my coding. That means that each function you define CAN BE a separate task. However, it can be dangerous. In a MAIN Forever loop, if you keep calling the same function over and over and this function has its own forever loop that never ends, each call will create a new instance of that function... It is not a problem for your example since your functions have no loops. Look at the following simple example: In this example, the main program is not a loop, it just call Test1 and prints END OF Main. The Function Test1 has a repeat loop that wait 1 seconds every loop then prints END OF Test1 task. In the time line, END OF Main will print as soon as you RUN the program. Actually, the Program RUNs and ENDs immediately. But 5 sec later, you will see in the status window: END OF Test1 task... Another example: In this example, 2 independant task for flashing Output 1 and output 2 independantly. And in the main loop, I made sure I "start" the task only once! Because those tasks have their own forever loop. Then in the main loop, I also make the Output C to follow the Touch sensor on Input 1. and it is still very responsive. We have clearly here, parallelism... HOWEVER, This is NOT the behaviour we wish for simple functions. Functions should be sub routines WITH NO forever loop. Functions SHOULD be synchronized with their Main loop. In the next versions, I will synch the built-in blockly functions. So in the first example above, the result is that the program will run, wait for 5 sec, then it will print END OF Test1 task and then print END Of Main, and Program will finish. The second example will not work anymore as the main loop will wait for the firt function call to return will never happens... The forever loop in this function would become the main loop... Also, I will add a new block TASK similar to functions but with a bit more features... Task will be Asynch from each other. Stay tuned...
  3. I added RCX Motor (Output) command caching into the code so it will send the Same consecutive command through serial only once. I did not cache the "Flip" command. I struggled a bit with the auto update again so if your page does not update by itself, use ctrl-shift-r to force the browser to update... You should get the following in the footer bar: Version: 2026-03-30-2250
  4. A blockly page is actually only one task or THREAD as they call it but it so fast that you can emulate somehow multitasking. I come from Industrial world, and in this world they have PLC's (Programmable Logic Controller) which is used to automate processes that involve often hundreds of sensors, motors, valves etc. They now have the notion of tasks but often, we use one task only with many "Routines", "sub-Routines" (Like Functions). The PLC are so fast and they do a forever loop... (Scan time is microseconds to milliseconds) It's like an Arduino type of programming that has a Setup routine and a Main Loop. So in a forever loop, as much as possible, you do not use "blocking" instructions like other repeat forever or Wait until, or Wait x seconds... those just blocks everything and if you want to monitor some touch sensors as quickly as possible, this is not the way to go. (That is the reason why I created non blocking timers. Moreover, I programed the timer so on completion, they can do an independant code.) (I might also implement more events eventually.) So if we take your exemple where you monitor 3 sensor inputs, since you use a fast forever loop, it behaves like you have 3 independant tasks... - Task 1: Monitor Sensor 2 continuously and do actions accordingly, - Task 2: Monitor Sensor 3 continuously and do actions accordingly, - Task 3: Monitor Sensor 4 continuously and do actions accordingly, And everything looks to be running independant . That is the way industrial PLC works. One fast forever loop, non blocking instructions, everything, input monitoring (polling), activating, deactivating outputs, everything looks independant... But with PLC, when a condition is true, they can keep energizing an output every scan. With Interface B, we cannot write the same command through serial every scan of the forever loop. That is why PLC philosophy is not ideal in this case but I did some caching for most output commands to make sure same commands are sent once.
  5. @Toastie, I think you'll have your Blockly Expert Certificate very soon ;-) You're progressing fast! You will become our Blockly teacher and teach to Wapata! Do you speak French? (I do as I'm french canadian if you didn't notice my accent in my writing lol) The new version should fix the blocking dialog window problem now. (I replaced the built in prompts and confirm dialog with new custom ones) Version: 2026-03-30-1519
  6. I just noticed that if you take too long to create a variable with its Dialog window, or using the confirm diablog window , it actually blocks the background programs and eventually, the Lego Interface disconnects. As soon as we connect a Lego Interface B, it starts reading continuously the 19 bytes streams... So this is interrupted by those modal dialog window... I'll try to find a fix for this and let you know.
  7. @Toastie No, I don't think so. The Sensor variable appears in the variable category, so it must be global. Don't forget that the basic of blockly is to make it easy for children. But still, doing it this way makes the program neat... I'm suprised that "3", "7" is working... As I said, they made it very simple so you don't need to think about conversion etc... You cannot use a Text directly in the Set Output ON block. But using a variable before might do the conversion internally of text number into number... But it will not convert a Letter to a number. However, if you still want to assign output port letters to your OutFwd and OutRev variable, you can still use the "Constant" variable that I provide for you to use anywhere in your program. They are in the Lego B -> Output Single Port Category at the top.
  8. @Gunners TekZone, @Toastie, @Wapata and all the others, I added the "Save As" button. The "clear" button has been replaced by a "New" button. (New Project). Which will clear the area and put back the project name to default. The last Folder used should be retain in a same session only. If you close and open the lego blockly page, it will revert to default folder (Downloads) until you save as or load a project... The save button will always now overwrite the same project file name. I also added the "New Edits" detection since the last save and you will have an "unsaved changes exist" indicator (Black Dot) on the left of the file name. When Unsaved edits exist, you will be asked for confirmation when you click on Load or New button... Latest Version: 2026-03-30-1212
  9. This function you gave in example, does not make a lot of sense though. The input variable should be "Sensor", then when you call the function, you connect Sensor_3 to Sensor, and later in your code, you may call again you function but this time, Sensr_4 connects to Sensor... Inside your function, you whould then only use "Sensor" variable.If you want to explictely use Sensor_3 inside the function, there is no need to use input variable... just use Sensor_3 variable already available as a global anyway. For the USB Tower, since I don't own one yet, I did not check what work has been done already to get it working on modern OS... The code area, I mean the Blockly code area where you drag blocks from the toolbox to make you blockly program.
  10. @Gunners TekZone, @Toastie, I do check for replies and even have three retries... But after 3 retries, if I do not get any reply, well, I just send an error to the chrome console (Press F12 to see the console) and keep going... I'll check if I display an error in the status window, might not do it at the moment. But the thing is, I do not stop the program for this. For the Rcx Input Value block, it does not return a boolean as I showed in a previous post, if the Input is configured as a touch sensor, it will return 0 or 1. See the example in post:
  11. Hello @Gunners TekZone, glad to see you back testing! - No Save As. Indeed, for now I wanted to keep it VERY simple. But I take good note of that... - A saved program doesn't retain and reconnect device connections. But the Name is retained as long as you connect your device BEFORE loading your saved code. As fas as I know, there are no UNIQUE ids for connections and Chrome does not provide the "Com" port number used... I've heard they might give more flexibility in a future version of the web serial api... Anyway, for now, the procedure is, you need to connect to a device to use its Auto generated Device Name in Lego Blocks. For RCX, actually, the Brick does not have to be powered really but the IR tower has to be connected. I still have a note to improve eventually the Device Naming and connect etc. But again, for now, it is VERY simple, Device Name are generated when you connect them, and the Device you select in Lego Blocks are retained in the saved files... But if you load your file when no device connected, the blocs will select no device... It may become difficult if you have many devices, so you may have to take notes LegoB1 is COM19, Rcx1 is COM5, LegoB2 is COM12 etc... - I tried having two RCX's online at the same time: I do not think 2 RCX with the same IR Tower can work... in parallel... I cannot test as I have only one but I do not see the gain... However, 2 IR tower, opposite direction, might work independantly. The MSG instruction trick here is the best I think. Thank you very much for your observations and suggestions. Always VERY appreciated!
  12. @Toastie, I think I fixed the issue with the Function blocks. I tested the following with success: I added a FOOTER and the version should now be: Version: 2026-03-29-1947
  13. I'm glad to see this thread a bit busier ;-) @Toastie, It appears that the function blocks (part of blockly internals) are not working anymore. I must have broken something and will look into that. I don't know much about blockly functions yet but it is a great way to make more object oriented programming. So if your main repeat forever loop becomes more complex, you can use function to modularize your program. When you drag a function block into the code area, you can rename it and it creates automatically in the toolbox, category Functions, a calling block for your function. You can the use the called block into your Main Repeat loop. I don't know but I doubt there is the notion of local variable. I would believe that all variables are Global... I have to test more... Also, when you create input variable for the function, it creates X by default and you can see this x variable in the Variable Category of the toolbox. If you right click on the variable in the toolbox, you can rename it... I think you're right, ChangeOutputA(value or variable) would be the same as a Function with no return value. Let me fix the Function blocks so you can test it without issues.
  14. Both USB to Serial and BT to Serial adapters are seen the same for the online Lego Blockly and it uses the webserial API for both (BT serial adapter generates a "COM" port in the windows device manager for example). I had to do a little something in the code though to have it run on ANDROID phone/tablet as there is no "COM" ports. But it still use the webserial API...
  15. @Wapata, The "Power" must be a number from 0 to 7 (3 bits, 000 to 111 binary), the program "AND"'s your number with 7 (111) whatever number you give, so 8 = 1000 binary AND 0111 = 0000= pwr 0 the lowest power. I just added tooltip on the Lego B power Block to inform about the range 0-7 of the power. As @Toastie said, the LegoBx name is saved with your project (if you use the save button) but you have to "load" back your program after reconnecting your com port(s) that generates the Device Name automatically. I might try to change this in the future but for now, it was for me the simplest way to do things.
×
×
  • Create New...