Clear, printString created

A project log for Barnabas Blocks Upgrade - BIG 2021

Webserial API webtool to upload Arduino code.

richardrichard 08/23/2021 at 16:508 Comments


Hello all!

I believe this week's assignment was to create specific blocks with ezDisplay functionality. There were three blocks to my recollection we were supposed to create being, delay, clear and printString. If I'm missing something please post a comment so I can get to work before or ON Tuesday.

One thing that I am not too clear on is if we are going to be able to import the libraries that ezDisplay requires. If that is possible, (and I have no idea how it's done! lol), then I guess the C code generation is as simple as the function signature. At the very least we need to find a way to import the library that the C functions that we will need call upon(for example, clear(), or printChar(), printString()). I wasn't sure the direction we were planning to go so I created C code to mirror the C code for the actual functions themselves as you can see in my screenshots. Delay was already given, so no problem there.

Looking forward to discussing more on how we should proceed on Tuesday! One silver lining to this exercise for me is that I believe we can now create ANY block to serve ANY function so long as the proper libraries are referenced. Please teach me how to do this on Tuesday! OR If it is assigned to us I will google my brains out this week.


Dante wrote 08/23/2021 at 23:01 point

There is a way to define things. Two examples:

In Arduino, a pin needs to have its "mode" set in the setup() function before it can be used. Therefore, every block that takes input from a block tells Blockly to add a "setup". For example, this code is from the block that reads the status of a pin:

Blockly.Arduino.setups_["setup_output_" + pin] = "pinMode(" + pin + ", INPUT_PULLUP);")

Notice how this is isn't returned, but is instead added to the setups_ list.

There are also "definitions" in Blockly which are at the top of the file, i.e. NOT in setup(). Functionality like controlling servo motors requires the library (which is built-in, but not imported/included by default) Servo.h. Therefore, we find this in the servo block generator to do the include properly:

Blockly.Arduino.definitions_['define_servo'] = '#include <Servo.h>'

You can use code like this to create include calls and anything else that is not part of your block but is required to run its code. Just change the name (define_servo in the second example) and the code at the end.

Hope this helps.

  Are you sure? yes | no

Edward Li wrote 08/23/2021 at 23:49 point

Thanks, Dante!

  Are you sure? yes | no

richard wrote 08/23/2021 at 23:49 point

Can you walk me through this tomorrow before our meeting? I'm at about 75% in understanding ;)

  Are you sure? yes | no

Dante wrote 08/24/2021 at 00:29 point


  Are you sure? yes | no

richard wrote 08/23/2021 at 16:52 point

Additionally, just scouring through all the code.. Blocklyduino developers are geniuses. It's so meticulously fine-tuned, detailed, well thought out. I'm amazed that people were able to do this and someday hope to get on that level.

  Are you sure? yes | no

Edward Li wrote 08/23/2021 at 17:00 point

👍 glad that you're inspired! 

  Are you sure? yes | no

Edward Li wrote 08/23/2021 at 17:10 point

Nice Richard! To answer your question regarding the tasks, we also discussed setfontsize

  Are you sure? yes | no

richard wrote 08/23/2021 at 18:29 point

I'll get on it!

  Are you sure? yes | no