Hi,
I’ve recently added an mBlock extension that adds blocks to access the Pixy2 camera API:
Although it works, I would like to streamline this if possible but couldn’t see how to do this. The Pixy 2 API (https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:ccc_api) includes an array of objects it has detected (Pixy2 also calls these “blocks” so don’t get confused). The attributes of these objects can be accessed via member variables e.g.:
- pixy.ccc.blocks[0].m_signature (signature)
- pixy.ccc.blocks[0].m_x (x position)
- pixy.ccc.blocks[0].m_y (y position)
- etc…
I tried to create a single “get” block which had two parameters:
- Array index
- Member variable (via dropdown)
However, whatever way I tried this, I ended up with quotes in the Arduino code and this doesn’t work e.g.
- pixy.ccc.blocks[0].“m_signature”
So I could get this working, I created a separate mBlock block explicitly for each member variable and just passed in the array index. See the following snippet:
[
"r",
"get block %n signature",
"get block signature",
0,
{
"inc" : "#include <SPI.h>\n#include \"Pixy2.h\"\n",
"def" : "Pixy2 pixy;\n",
"setup" : "pixy.init();\n",
"work" : "pixy.ccc.blocks[(int) {0}].m_signature",
"loop" : ""
}
],
[
"r",
"get block %n x pos",
"get block x pos",
0,
{
"inc" : "#include <SPI.h>\n#include \"Pixy2.h\"\n",
"def" : "Pixy2 pixy;\n",
"setup" : "pixy.init();\n",
"work" : "pixy.ccc.blocks[(int) {0}].m_x",
"loop" : ""
}
],
Does anyone have a suggestion on how I could consolidate the multiple mBlock blocks into a single one with valid Arduino code as per my original plan?