Arduino support for user defined blocks


#1

I have an mBlock script that includes two user defined blocks from the Data&Blocks section. This script runs fine from mBlock to mBot over Bluetooth.

When I try to upload this script to mBot so that it can run independently of mBlock, I receive an error that the user defined block was not declared in the scope of MePort.h.

Does Arduino support the use of user defined blocks?

C:\Program Files (x86)\mBlock\Arduino\arduino_debug.exe --upload --board arduino:avr:uno --port COM18 --verbose --preserve-temp-files C:\Users\jlifter\AppData\Roaming\com.makeblock.Scratch\Local Store\scratchTemp\project_____F_______7_3\project_____F_______7_3.ino
Loading configuration…
Initializing packages…
Preparing boards…
Verifying and uploading…
Using library Wire in folder: C:\Program Files (x86)\mBlock\Arduino\hardware\arduino\avr\libraries\Wire
Using library SoftwareSerial in folder: C:\Program Files (x86)\mBlock\Arduino\hardware\arduino\avr\libraries\SoftwareSerial
Using library MakeBlockDrive in folder: C:\Program Files (x86)\mBlock\Arduino\libraries\makeblock

C:\Program Files (x86)\mBlock\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files (x86)\mBlock\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\mBlock\Arduino\hardware\arduino\avr\variants\standard -IC:\Program Files (x86)\mBlock\Arduino\hardware\arduino\avr\libraries\Wire -IC:\Program Files (x86)\mBlock\Arduino\hardware\arduino\avr\libraries\SoftwareSerial -IC:\Program Files (x86)\mBlock\Arduino\libraries\makeblock\src C:\Users\jlifter\AppData\Local\Temp\build3936407204345654896.tmp\project_____F_______7_3.cpp -o C:\Users\jlifter\AppData\Local\Temp\build3936407204345654896.tmp\project_____F_______7_3.cpp.o
In file included from C:\Program Files (x86)\mBlock\Arduino\libraries\makeblock\src/Me7SegmentDisplay.h:68:0,
from C:\Program Files (x86)\mBlock\Arduino\libraries\makeblock\src/MeMCore.h:40,
from project_____F_______7_3.ino:5:
C:\Program Files (x86)\mBlock\Arduino\libraries\makeblock\src/MePort.h:88:17: error: variable or field ‘Movement’ declared void
#define M1 (0x09)
^
project_____F_______7_3.ino:9:22: note: in expansion of macro 'M1’
C:\Program Files (x86)\mBlock\Arduino\libraries\makeblock\src/MePort.h:88:17: error: variable or field ‘Movement’ declared void
#define M1 (0x09)
^
project_____F_______7_3.ino:20:22: note: in expansion of macro ‘M1’
project_____F_______7_3.ino: In function ‘void loop()’:
project_____F_______7_3.ino:43:21: error: ‘Movement’ was not declared in this scope
project_____F_______7_3.ino:46:25: error: ‘Movement’ was not declared in this scope
project_____F_______7_3.ino:49:33: error: ‘Movement’ was not declared in this scope
project_____F_______7_3.ino:54:39: error: ‘Movement’ was not declared in this scope
project_____F_______7_3.ino:59:39: error: ‘Movement’ was not declared in this scope
project_____F_______7_3.ino:66:39: error: ‘Movement’ was not declared in this scope
’Movement’ was not declared in this scope


#2

The problem that you are experiencing has to do with the use of macro names as variable names. In your custom block, you use M1 and M2 as variable names for the block. However, M1 and M2 are defined in the MePort.h file of the Makeblock libraries:

#define M1      (0x09)
#define M2      (0x0a)

If you change the names of the variables in your custom block, everything should compile fine.

Regards,

Chuck


#3

Yes. That works.
I’ll be careful how I name variables and parameters.
Thanks very much.


#4

No worries, I discuss that problem in my book, A Gentle Introduction to Robotics (link) along with other problems, etc. that are commonly encountered.

Glad to have been of help! :slight_smile: