mBlock 5 Extension: Set block value to arduino/C value


#1

Hello!

I am trying to accomplish something that I think would be simple, I’m just struggling to get it working correctly.

If I have a “number” block where in “Block Settings” within the “Upload transcode” section under the “declare” box I define “int test = 0;”

How do I access this variable “test” so the block displays and equals this value? I am able to do this in the javascript portion, but for my program I need to be able to do this for C values such as what I described above. Any help would be greatly appreciated.

Thanks,
Chris


#2

Hi Chris.Farr,

I’m not good at English so I’m not sure I understand it. However, I have started an extension and I am reading variables in C. You can see if that helps and if you have any questions, I am still available.


#3

Thank you for the great example! That looks like a fun extension! Your english is very clear.

This is helpful for arduino compatibility so thank you again. I think this helps to answer most of my question.

My remaining question is for how to get the values of the blocks to display when using sprites. If I wanted to use the value of the blue “Read PUSH” button in sprites would I be able to use C? Your code outputs “!digitalRead(g_pinPush)”, so this is an example of a reading I would like to assign to a variable in the sprite mode. I am struggling to do so as values only appear if I add to the “live mode handler”.

Is it possible to access C-variables from the java-script in the “live model handler”?

I hope I am clear! I am new at this so I am struggling with describing my goal.


#4

Hi Chris.Farr,

To use a button or value from the Arduino, you must go through the extension: Upload Mode Broadcast
Upload

Here is an example with a physical button Arduino and the reception by a sprite.

The problem is rather the opposite. I’m trying to send from a sprite to the Arduino. I would like Makeblock to explain to me why this is not working; (