I have defined a new extension for mBlock. The arduino code generated does not however correspond to my definition.
"def":"int pinA1 = 11;\nint pinA2 = 10;\nint pinB1 = 6;\nint pinB2 = 5;\nvoid L298control(int motors, int mode){\n if(motors == 1 || motors == 2) {\n switch (mode) {\n case 0: \n digitalWrite(pinA1,1) ;\n digitalWrite(pinA2,0);\n break;\n case 1: \n digitalWrite(pinA1,0);\n digitalWrite(pinA2,1);\n break;\n case 2: \n digitalWrite(pinA1,1);\n digitalWrite(pinA2,1);\n break;\n case 3: \n digitalWrite(pinA1,0);\n digitalWrite(pinA2,0);\n }\n}\nif(motors == 0 || motors == 2) {\n switch (mode) {\n case 0:\n digitalWrite(pinB1,0);\n digitalWrite(pinB2,1);\n break;\n case 1: \n digitalWrite(pinB1,1);\n digitalWrite(pinB2,0);\n break;\n case 2: \n digitalWrite(pinB1,1);\n digitalWrite(pinB2,1);\n break;\n case 3: \n digitalWrite(pinB1,0);\n digitalWrite(pinB2,0);\n }\n}\n}\n",
Somehow becomes
int pinA1 = 11;
int pinA2 = 10;
int pinB1 = 6;
int pinB2 = 5;
void L298control(int motors, int mode){
if(motors == 1 || motors == 2) {
switch (mode) {
case 0:
digitalWrite(pinA1,1) ;
digitalWrite(pinA2,0);
break;
case 1:
digitalWrite(pinA1,0);
digitalWrite(pinA2,1);
case 2:
digitalWrite(pinA1,1);
case 3:
}
if(motors == 0 || motors == 2) {
digitalWrite(pinB1,0);
digitalWrite(pinB2,1);
digitalWrite(pinB1,1);
digitalWrite(pinB2,0);
The second if-statement has lost a layer of switch-statement, and it is not terminated. But the problems start in the case 2 part of the first if statement.
This whole function works fine if I inline it in “work” instead of defining a function, but that leads to a lot of duplicated code.
Also, I can use tabulators in “work”, but not in “def”.
Can I work around this in some efficient manner? Or is there a secret beta of mBlock 5 for linux?