// Do not edit this file; automatically generated by build.py. 'use strict'; /* Licensed under the Apache License, Version 2.0 (the "License"): http://www.apache.org/licenses/LICENSE-2.0 */ Blockly.Python=new Blockly.Generator("Arduino");Blockly.Python.StaticTyping=new Blockly.StaticTyping;Blockly.Python.addReservedWords("Blockly,setup,loop,if,else,for,switch,case,while,do,break,continue,return,goto,define,include,HIGH,LOW,INPUT,OUTPUT,INPUT_PULLUP,true,false,integer,constants,floating,point,void,boolean,char,unsigned,byte,int,word,long,float,double,string,String,array,static,volatile,const,sizeof,pinMode,digitalWrite,digitalRead,analogReference,analogRead,analogWrite,tone,noTone,shiftOut,shitIn,pulseIn,millis,micros,delay,delayMicroseconds,min,max,abs,constrain,map,pow,sqrt,sin,cos,tan,randomSeed,random,lowByte,highByte,bitRead,bitWrite,bitSet,bitClear,bit,attachInterrupt,detachInterrupt,interrupts,noInterrupts"); Blockly.Python.ORDER_ATOMIC=0;Blockly.Python.ORDER_UNARY_POSTFIX=1;Blockly.Python.ORDER_UNARY_PREFIX=2;Blockly.Python.ORDER_MULTIPLICATIVE=3;Blockly.Python.ORDER_ADDITIVE=4;Blockly.Python.ORDER_SHIFT=5;Blockly.Python.ORDER_RELATIONAL=6;Blockly.Python.ORDER_EQUALITY=7;Blockly.Python.ORDER_BITWISE_AND=8;Blockly.Python.ORDER_BITWISE_XOR=9;Blockly.Python.ORDER_BITWISE_OR=10;Blockly.Python.ORDER_LOGICAL_AND=11;Blockly.Python.ORDER_LOGICAL_OR=12;Blockly.Python.ORDER_CONDITIONAL=13; Blockly.Python.ORDER_ASSIGNMENT=14;Blockly.Python.ORDER_NONE=99;Blockly.Python.PinTypes={INPUT:"INPUT",OUTPUT:"OUTPUT",PWM:"PWM",SERVO:"SERVO",STEPPER:"STEPPER",SERIAL:"SERIAL",I2C:"I2C/TWI",SPI:"SPI",FASTLED:"FASTLED",DHT:"DHT"};Blockly.Python.DEF_FUNC_NAME=Blockly.Python.FUNCTION_NAME_PLACEHOLDER_; Blockly.Python.init=function(a){Blockly.Python.includes_=Object.create(null);Blockly.Python.definitions_=Object.create(null);Blockly.Python.variables_=Object.create(null);Blockly.Python.codeFunctions_=Object.create(null);Blockly.Python.userFunctions_=Object.create(null);Blockly.Python.functionNames_=Object.create(null);Blockly.Python.setups_=Object.create(null);Blockly.Python.pins_=Object.create(null);Blockly.Python.variableDB_?Blockly.Python.variableDB_.reset():Blockly.Python.variableDB_=new Blockly.Names(Blockly.Python.RESERVED_WORDS_); var b=Blockly.Python.StaticTyping.collectVarsWithTypes(a);Blockly.Python.StaticTyping.setProcedureArgs(a,b);for(var c in b)"array"!=Blockly.Python.getArduinoType_(b[c])&&Blockly.Python.addVariable(c,Blockly.Python.getArduinoType_(b[c])+" "+Blockly.Python.variableDB_.getName(c,Blockly.Variables.NAME_TYPE)+";")}; Blockly.Python.finish=function(a){var b=[],c=[],d=[],e=[],f;for(f in Blockly.Python.includes_)b.push(Blockly.Python.includes_[f]);b.length&&b.push("\n");for(f in Blockly.Python.variables_)d.push(Blockly.Python.variables_[f]);d.length&&d.push("\n");for(f in Blockly.Python.definitions_)c.push(Blockly.Python.definitions_[f]);c.length&&c.push("\n");for(f in Blockly.Python.codeFunctions_)e.push(Blockly.Python.codeFunctions_[f]);for(f in Blockly.Python.userFunctions_)e.push(Blockly.Python.userFunctions_[f]); e.length&&e.push("\n");var g=[""],h="";void 0!==Blockly.Python.setups_.userSetupCode&&(h="\n"+Blockly.Python.setups_.userSetupCode,delete Blockly.Python.setups_.userSetupCode);for(f in Blockly.Python.setups_)g.push(Blockly.Python.setups_[f]);h&&g.push(h);delete Blockly.Python.includes_;delete Blockly.Python.definitions_;delete Blockly.Python.codeFunctions_;delete Blockly.Python.userFunctions_;delete Blockly.Python.functionNames_;delete Blockly.Python.setups_;delete Blockly.Python.pins_;Blockly.Python.variableDB_.reset(); b=b.join("\n")+d.join("\n")+c.join("\n");g="void setup() {"+g.join("\n ")+"\n}\n\n";a="void loop() {\n "+a.replace(/\n/g,"\n ")+"\n}\n\n";return b+g+a+e.join("\n")};Blockly.Python.addInclude=function(a,b){void 0===Blockly.Python.includes_[a]&&(Blockly.Python.includes_[a]=b)};Blockly.Python.addDeclaration=function(a,b){void 0===Blockly.Python.definitions_[a]&&(Blockly.Python.definitions_[a]=b)}; Blockly.Python.addVariable=function(a,b,c){var d=!1;if(c||void 0===Blockly.Python.variables_[a])Blockly.Python.variables_[a]=b,d=!0;return d};Blockly.Python.addSetup=function(a,b,c){var d=!1;if(c||void 0===Blockly.Python.setups_[a])Blockly.Python.setups_[a]=b,d=!0;return d}; Blockly.Python.addFunction=function(a,b){if(void 0===Blockly.Python.codeFunctions_[a]){var c=Blockly.Python.variableDB_.getDistinctName(a,Blockly.Generator.NAME_TYPE);Blockly.Python.codeFunctions_[a]=b.replace(Blockly.Python.DEF_FUNC_NAME,c);Blockly.Python.functionNames_[a]=c}return Blockly.Python.functionNames_[a]}; Blockly.Python.reservePin=function(a,b,c,d){void 0!==Blockly.Python.pins_[b]?Blockly.Python.pins_[b]!=c?a.setWarningText(Blockly.Msg.ARD_PIN_WARN1.replace("%1",b).replace("%2",d).replace("%3",c).replace("%4",Blockly.Python.pins_[b]),d):a.setWarningText(null,d):(Blockly.Python.pins_[b]=c,a.setWarningText(null,d))};Blockly.Python.scrubNakedValue=function(a){return a+";\n"}; Blockly.Python.quote_=function(a){a=a.replace(/\\/g,"\\\\").replace(/\n/g,"\\\n").replace(/\$/g,"\\$").replace(/'/g,"\\'");return'"'+a+'"'}; Blockly.Python.scrub_=function(a,b){if(null===b)return"";var c="";if(!a.outputConnection||!a.outputConnection.targetConnection){var d=a.getCommentText();d&&(c+=this.prefixLines(d,"// ")+"\n");for(var e=0;e 0) {\n "+ d+" = Serial1.read();\n}\n"+b;else if("array"===c){a=a.getFieldValue("LENGTH");c="{";for(e=0;e 0) {\n BTserialDataReceived = Serial1.readStringUntil("\\r\\n");\n }\n if (BTgetSerialDataValue(BTserialDataReceived, \'|\', 0) == "SOF") {\n return 1;\n } else {\n return 0;\n }\n}\n'); Blockly.Python.addFunction("BTgetSerialDataValue",'String BTgetSerialDataValue(String data, char separator, int index)\n{\n int found = 0;\n int strIndex[] = {0, -1};\n int maxIndex = data.length() - 1;\n for (int i = 0; i <= maxIndex && found <= index; i++) {\n if (data.charAt(i) == separator || i == maxIndex) {\n found++;\n strIndex[0] = strIndex[1] + 1;\n strIndex[1] = (i == maxIndex) ? i + 1 : i;\n }\n }\n return found > index ? data.substring(strIndex[0], strIndex[1]) : "";\n}\n'); return'boolean BTserialReceiveCheck_ = BTserialDataFilter();\nif (!BTserialReceiveCheck_) {\n Serial.println("Error receiving data from Bluetooth Module.");\n return;\n }\n'};Blockly.Python.bluetooth_intercomms_receive_getData=function(a){var b=parseInt(a.getFieldValue("INDEX"))+1;a=a.getFieldValue("TYPE");return["BTgetSerialDataValue(BTserialDataReceived, '|', "+b+")"+a,Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.bluetooth_intercomms_send_old=function(a){Blockly.Python.addDeclaration("wifi_dataTransfer_checkbit","#define SOP '<'\n#define EOP '>'\n");var b=a.getFieldValue("BAUD");Blockly.Python.addSetup("mainwifi_setup","Serial1.begin("+b+");");b=a.itemCount_;for(var c=b+"+2",d="unsigned char DataOut_["+c+"];\nDataOut_[0] = SOP;\n",e=1;e'\n");var b=a.getFieldValue("LENGTH");a=a.getFieldValue("BAUD");Blockly.Python.addSetup("mainwifi_setup","Serial1.begin("+a+");");Blockly.Python.addDeclaration("wifi_dataTransfer_MsgReceiveStatus","bool started = false;\nbool ended = false;\nint index_i;\n");Blockly.Python.addDeclaration("BT_interCommms_receive","int BTIC_receive["+b+"] = {0};");Blockly.Python.addFunction("mainwifi_dataIn_function", "int handleDataIn() {\n while (Serial1.available() > 0) {\n int inChar = Serial1.read();\n if(inChar == SOP) {\n index_i = 0;\n started = true;\n ended = false;\n } else if(inChar == EOP) {\n ended = true;\n break;\n }else if((index_i < "+b+")&&started&&(!ended)) {\n BTIC_receive[index_i] = inChar;\n index_i++;\n }\n }\n if(started && ended) {\n return 1;\n } else {\n return 0;\n }\n}\n");return"boolean receiveMsgsuccess_ = handleDataIn();\n"}; Blockly.Python.bluetooth_intercomms_receive_getData_old=function(a){return["BTIC_receive["+a.getFieldValue("INDEX")+"]",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.bluetooth_at_slave=function(a){a=a.getFieldValue("BAUD");Blockly.Python.addDeclaration("BT_at_slave_decl","int bluetoothATModeserialSendState = 0;\nchar c = ' ';\n");Blockly.Python.addSetup("BT_at_slave_setup"," Serial.begin("+a+");\n Serial1.begin(38400);\n");Blockly.Python.addFunction("BT_at_slave_func","void bluetoothATModeInteractive() {\n while (Serial1.available() > 0) {\n c = Serial1.read();\n Serial.write(c);\n }\n while (Serial.available() > 0) {\n c = Serial.read();\n Serial1.write(c);\n }\n}\n");return' bluetoothATModeInteractive();\n // Slave\n if ( (millis() / 1000) % 50 == 5 && bluetoothATModeserialSendState == 0) {\n Serial.println(" ____ _ _ _ _ ");\n Serial.println(" | __ ) | | _ _ ___ | |_ ___ ___ | |_ | |__ ");\n Serial.println(" | _ \\ | | | | | | / _ \\ | __| / _ \\ / _ \\ | __| | \'_ \\ ");\n Serial.println(" | |_) | | | | |_| | | __/ | |_ | (_) | | (_) | | |_ | | | |");\n Serial.println(" |____/ |_| \\__,_| \\___| \\__| \\___/ \\___/ \\__| |_| |_|");\n Serial.println("");\n Serial.println(" ____ _ ");\n Serial.println(" / ___| | | __ _ __ __ ___ ");\n Serial.println(" \\___ \\ | | / _` | \\ \\ / / / _ ");\n Serial.println(" ___) | | | | (_| | \\ V / | __/");\n Serial.println(" |____/ |_| \\__,_| \\_/ \\___|");\n Serial.println("");\n Serial.println("");\n Serial.println("1. Testing communication:");\n Serial.print("- ");\n Serial1.write("AT\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 6) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 7 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("2. Reset previous configuration:");\n Serial.print("- ");\n Serial1.write("AT+ORGL\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 8) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 10 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("3. Set up UART configuration: AT+UART='+ a+',0,0");\n Serial.print("- ");\n Serial1.write("AT+UART='+a+',0,0\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 11) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 13 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("4. Set up pairing mode, prevent outside connection: AT+CMODE=0");\n Serial.print("- ");\n Serial1.write("AT+CMODE=0\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 14) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 16 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("5. Set up pairing mode, set as Slave Mode: AT+ROLE=0");\n Serial.print("- ");\n Serial1.write("AT+ROLE=0\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 17) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 18 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("6. Getting MAC address:");\n Serial.print("- ");\n Serial1.write("AT+ADDR\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 19) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 21 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("7. Done, reset bluetooth module to normal state.");\n Serial.print("- ");\n Serial1.write("AT+RESET\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 22) {\n bluetoothATModeserialSendState = 0;\n }\n'}; Blockly.Python.bluetooth_at_master=function(a){var b=a.getFieldValue("BAUD");a=a.getFieldValue("ADDR").replace(/:/g,",");Blockly.Python.addDeclaration("BT_at_master_decl","int bluetoothATModeserialSendState = 0;\nchar c = ' ';\n");Blockly.Python.addSetup("BT_at_master_setup"," Serial.begin("+b+");\n Serial1.begin(38400);\n");Blockly.Python.addFunction("BT_at_master_fun","void bluetoothATModeInteractive() {\n while (Serial1.available() > 0) {\n c = Serial1.read();\n Serial.write(c);\n }\n while (Serial.available() > 0) {\n c = Serial.read();\n Serial1.write(c);\n }\n}\n"); return' bluetoothATModeInteractive();\n // Master\n if ( (millis() / 1000) % 50 == 5 && bluetoothATModeserialSendState == 0) {\n Serial.println(" ____ _ _ _ _ ");\n Serial.println(" | __ ) | | _ _ ___ | |_ ___ ___ | |_ | |__ ");\n Serial.println(" | _ \\ | | | | | | / _ \\ | __| / _ \\ / _ \\ | __| | \'_ \\ ");\n Serial.println(" | |_) | | | | |_| | | __/ | |_ | (_) | | (_) | | |_ | | | |");\n Serial.println(" |____/ |_| \\__,_| \\___| \\__| \\___/ \\___/ \\__| |_| |_|");\n Serial.println("");\n Serial.println(" __ __ _ ");\n Serial.println(" | \\/ | __ _ ___ | |_ ___ _ __ ");\n Serial.println(" | |\\/| | / _` | / __| | __| / _ \\ | \'__|");\n Serial.println(" | | | | | (_| | \\__ \\ | |_ | __/ | | ");\n Serial.println(" |_| |_| \\__,_| |___/ \\__| \\___| |_| ");\n Serial.println("");\n Serial.println("");\n Serial.println("1. Testing communication:");\n Serial.print("- ");\n Serial1.write("AT\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 6) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 7 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("2. Reset previous configuration:");\n Serial.print("- ");\n Serial1.write("AT+ORGL\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 8) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 10 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("3. Set up UART configuration: AT+UART='+ b+',0,0");\n Serial.print("- ");\n Serial1.write("AT+UART='+b+',0,0\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 11) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 13 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("4. Set up pairing mode, prevent outside connection: AT+CMODE=0");\n Serial.print("- ");\n Serial1.write("AT+CMODE=0\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 14) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 16 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("5. Set up pairing mode, set as Master Mode: AT+ROLE=1");\n Serial.print("- ");\n Serial1.write("AT+ROLE=1\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 17) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 18 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("6. Binding slave device:");\n Serial.print("- ");\n Serial1.write("AT+BIND='+ a+'\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 19) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 21 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("7. Done, reset bluetooth module to normal state.");\n Serial.print("- ");\n Serial1.write("AT+RESET\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 22) {\n bluetoothATModeserialSendState = 0;\n }\n'}; Blockly.Python.bluetooth_at_interaction=function(a){a=a.getFieldValue("bluetooth_at_interaction_baud");Blockly.Python.addDeclaration("bluetooth_at_interaction_declare","char c = ' ';\n");Blockly.Python.addSetup("bluetooth_at_interaction_setup","Serial.begin("+a+");\nSerial1.begin("+a+");\n");Blockly.Python.addFunction("bluetooth_at_interaction_function","void _bluetoothATmode() {\n if (Serial1.available())\n Serial.write(Serial1.read());\n if (Serial.available())\n Serial1.write(Serial.read());\n}\n"); return"_bluetoothATmode();\n"};Blockly.Python.blynk={}; Blockly.Python.blynk_setup=function(a){var b=a.getFieldValue("AUTH"),c=a.getFieldValue("SSID");a=a.getFieldValue("PW");Blockly.Python.addDeclaration("blynk_define","#define BLYNK_PRINT Serial\n");Blockly.Python.addInclude("blynk_setup","#include \n#include \n");Blockly.Python.addDeclaration("Blynk_init",'char auth[] = "'+b+'";\nchar ssid[] = "'+c+'";\nchar pass[] = "'+a+'";\n');Blockly.Python.addSetup("Blynk_begin","Blynk.begin(auth,ssid,pass);\n");return"Blynk.run();\n"}; Blockly.Python.blynk_write=function(a){var b=a.getFieldValue("PIN");a.getFieldValue("MOD");var c="BLYNK_WRITE("+b+")\n{\n";a=Blockly.Python.statementToCode(a,"STATEMENT");Blockly.Python.addFunction("Blynk_Write"+b,c+(a+"\n}\n"));return""};Blockly.Python.blynk_write_getData=function(a){var b=a.getFieldValue("MOD");return["zeRGBa"==b||"Joystick"==b?"param["+a.getFieldValue("SELINDEX")+"].asInt()":"param.asInt()",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.blynk_write_getData_joystick=function(a){var b=a.getFieldValue("MOD");return["zeRGBa"==b||"Joystick"==b?"param["+a.getFieldValue("SELINDEX")+"].asInt()":"param.asInt()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.blynk_write_getData_zeRGBa=function(a){var b=a.getFieldValue("MOD");return["zeRGBa"==b||"Joystick"==b?"param["+a.getFieldValue("SELINDEX")+"].asInt()":"param.asInt()",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.blynk_write_getData_GraOrAcc=function(a){return["param["+a.getFieldValue("SELINDEX")+"].asFloat()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.blynk_write_getData_GPS=function(a){return["param["+a.getFieldValue("SELINDEX")+"].asFloat()",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.blynk_read=function(a){for(var b=a.getFieldValue("PIN"),c="BLYNK_READ("+b+")\n{\n",d=0;d>3)+32*(b.g>>2)+(b.b>>3);b=b.toString(16);if(4>b.length)for(;4>b.length;)b="0"+b;return a?"0x"+b:null} Blockly.Python.color_analyzer_setup=function(a){Blockly.Python.addInclude("wire.h","#include \n");Blockly.Python.addInclude("colorAnalyzeDef",'#include "Adafruit_TCS34725.h"\n\nAdafruit_TCS34725 tcs = Adafruit_TCS34725();\n');Blockly.Python.addSetup("colorAnalyzeSetup","tcs.begin();\n");Blockly.Python.addDeclaration("Color_analyzer_colors","uint16_t red, green, blue, c;\n");return"tcs.getRawData(&red, &green, &blue, &c);\nred = red*256/c;\ngreen = green*256/c;\nblue = blue*256/c;\nif (red > 255) red = 255;\nif (green > 255) green = 255;\nif (blue > 255) blue = 255;\n"}; Blockly.Python.set_color=function(a){return[a.getFieldValue("COLOR"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.read_r=function(a){return["red",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.read_g=function(a){return["green",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.read_b=function(a){return["blue",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.set_colorRGB=function(a){var b=Blockly.Python.valueToCode(a,"RED_VAL",Blockly.Python.ORDER_ATOMIC),c=Blockly.Python.valueToCode(a,"GREEN_VAL",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"BLUE_VAL",Blockly.Python.ORDER_ATOMIC);return["("+b+","+c+","+a+")",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.isColorRGB=function(a){a=a.getFieldValue("COLOR")||"r";var b="int isColorRGB_"+a+"() {\n";switch(a){case "r":b+=" if (red >= 200 && green <= 50 && blue <= 50)\n return 1;\n else\n return 0;\n";break;case "g":b+=" if (green >= 200 && red <= 50 && blue <= 50)\n return 1;\n else\n return 0;\n";break;case "b":b+=" if (blue >= 200 && green <= 50 && red <= 50)\n return 1;\n else\n return 0;\n"}Blockly.Python.addFunction("isColor_"+a,b+"}\n");return["isColorRGB_"+ a+"()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.colour={};Blockly.Python.colour_picker=Blockly.Python.noGeneratorCodeInline;Blockly.Python.colour_random=Blockly.Python.noGeneratorCodeInline;Blockly.Python.colour_rgb=Blockly.Python.noGeneratorCodeInline;Blockly.Python.colour_blend=Blockly.Python.noGeneratorCodeInline;Blockly.Python.define={};Blockly.Python.define=function(a){var b=Blockly.Python.valueToCode(a,"define_init",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"define_variable",Blockly.Python.ORDER_ATOMIC);Blockly.Python.addDeclaration("define_init","#define\t"+b+"\t"+a,!1);return""};Blockly.Python.define_var=function(a){Blockly.Python.valueToCode(a,"define_variable",Blockly.Python.ORDER_ATOMIC);return["",Blockly.Python.ORDER_NONE]};Blockly.Python.env={};Blockly.Python.env_init=function(a){Blockly.Python.addDeclaration("env_init_",'#include "DHT.h"\n #define DHTTYPE DHT11\n');Blockly.Python.addSetup("env_init_2",'Serial.println("DHTxx test!"); \n');return""}; Blockly.Python.iot_read_val=function(a){a=a.getFieldValue("val_type");"mic"==a?(Blockly.Python.addDeclaration("iot_mic_decl","#define PIN_MIC A2\n"),Blockly.Python.addSetup("iot_mic_setup","pinMode(PIN_MIC, INPUT);"),a="analogRead(PIN_MIC)"):"light"==a?(Blockly.Python.addDeclaration("iot_light_decl","#define PIN_LIGHT A1\n"),Blockly.Python.addSetup("iot_light_setup","pinMode(PIN_LIGHT, INPUT);"),a="analogRead(PIN_LIGHT)"):a="dht.readHumidity()";return[a,Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.iot_read_mic=function(a){a=a.getFieldValue("env_sensor_mic");Blockly.Python.addDeclaration("iot_mic_decl","#define PIN_MIC "+a);Blockly.Python.addSetup("iot_mic_setup","pinMode(PIN_MIC, INPUT);");return["analogRead(PIN_MIC)",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.iot_read_light=function(a){a=a.getFieldValue("env_sensor_light");Blockly.Python.addDeclaration("iot_light_decl","#define PIN_LIGHT "+a);Blockly.Python.addSetup("iot_light_setup","pinMode(PIN_LIGHT, INPUT);");return["analogRead(PIN_LIGHT)",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.iot_read_humid=function(a){a=a.getFieldValue("env_sensor_humid");Blockly.Python.addDeclaration("humid_temp_init","#define DHTPIN "+a+"\nDHT dht(DHTPIN, DHTTYPE);\n");Blockly.Python.addSetup("humid_temp_setup","dht.begin();\n");return["dht.readHumidity()",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.iot_read_temp=function(a){var b=a.getFieldValue("env_sensor_temp");Blockly.Python.addDeclaration("humid_temp_init","#define DHTPIN "+b+"\nDHT dht(DHTPIN, DHTTYPE);\n");Blockly.Python.addSetup("humid_temp_setup","dht.begin();\n");b="dht.readTemperature(";b="c"==a.getFieldValue("temp_unit")?b+")":b+"true)";return[b,Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.iot_buzzer=function(a){var b=a.getFieldValue("PINSNUM");a=Blockly.Python.valueToCode(a,"FREQUENCY",Blockly.Python.ORDER_ATOMIC);Blockly.Python.addSetup("iot_buzzer_"+b,"pinMode("+b+", OUTPUT);\n",!1);return"tone("+b+","+a+");\n"};Blockly.Python.iot_nobuzzer=function(a){a=a.getFieldValue("PINSNUM");Blockly.Python.addSetup("iot_buzzer_"+a,"pinMode("+a+", OUTPUT);\n",!1);return"noTone("+a+");\n"}; Blockly.Python.iot_set_rgb=function(a){var b=a.getFieldValue("env_sensor_rgbPin_r"),c=a.getFieldValue("env_sensor_rgbPin_g"),d=a.getFieldValue("env_sensor_rgbPin_b");Blockly.Python.addDeclaration("pin_rgb","int redPin = "+b+";\n int greenPin = "+c+";\n int bluePin = "+d+";");Blockly.Python.addSetup("setup_rgb","pinMode(redPin, OUTPUT);\npinMode(greenPin, OUTPUT);\n pinMode(bluePin, OUTPUT);\nsetColor(0,0,0);\n");Blockly.Python.addFunction("setcolor_rgb","void setColor(int red, int green, int blue)\n{\n red = 255 - red;\n green = 255 - green;\n blue = 255 - blue;\n analogWrite(redPin, red);\n analogWrite(greenPin, green);\n analogWrite(bluePin, blue);\n}\n"); b=Blockly.Python.valueToCode(a,"RED_VAL",Blockly.Python.ORDER_ATOMIC);c=Blockly.Python.valueToCode(a,"GREEN_VAL",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"BLUE_VAL",Blockly.Python.ORDER_ATOMIC);return"setColor("+b+","+c+","+a+");"};Blockly.Python.hci={};Blockly.Python.HID_setup=function(a){Blockly.Python.addInclude("keyboard",'#include "Keyboard.h"');Blockly.Python.addInclude("Mouse",'#include "Mouse.h"');Blockly.Python.addSetup("HID","Mouse.begin();\nKeyboard.begin();\n");return""}; Blockly.Python.HID_mouse_move=function(a){var b="",c=a.getFieldValue("mouse_towards");a=a.getFieldValue("mouse_distance");switch(c){case "KEYPAD_UP":b="Mouse.move(0, -"+a+");\n";break;case "KEYPAD_DOWN":b="Mouse.move(0, "+a+");\n";break;case "KEYPAD_LEFT":b="Mouse.move(-"+a+", 0);\n";break;case "KEYPAD_RIGHT":b="Mouse.move("+a+", 0);\n"}return b};Blockly.Python.HID_mouse_click=function(a){return"Mouse.click("+a.getFieldValue("CLICK")+");\n"}; Blockly.Python.HID_mouse_press=function(a){return"Mouse.press("+a.getFieldValue("CLICK")+");\n"};Blockly.Python.HID_mouse_release=function(a){return"Mouse.release("+a.getFieldValue("CLICK")+");\n"};Blockly.Python.HID_keyboard_press=function(a){return"Keyboard.press("+a.getFieldValue("keyboard_press")+");\n"};Blockly.Python.HID_keyboard_release=function(a){return"Keyboard.release("+a.getFieldValue("keyboard_press")+");\n"};Blockly.Python.HID_keyboard_releaseAll=function(a){return"Keyboard.releaseAll();\n"};Blockly.Python.IO={};Blockly.Python.io_digitalwrite=function(a){var b=Blockly.Python.valueToCode(a,"PIN",Blockly.Python.ORDER_ATOMIC)||"1",c=Blockly.Python.valueToCode(a,"STATE",Blockly.Python.ORDER_ATOMIC)||"LOW";Blockly.Python.reservePin(a,b,Blockly.Python.PinTypes.OUTPUT,"Digital Write");Blockly.Python.addSetup("io_"+b,"pinMode("+b+", OUTPUT);",!1);return"digitalWrite("+b+", "+c+");\n"}; Blockly.Python.io_digitalread=function(a){var b=Blockly.Python.valueToCode(a,"PIN",Blockly.Python.ORDER_ATOMIC)||"1";Blockly.Python.reservePin(a,b,Blockly.Python.PinTypes.INPUT,"Digital Read");Blockly.Python.addSetup("io_"+b,"pinMode("+b+", INPUT);",!1);return["digitalRead("+b+")",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.io_builtin_led=function(a){var b=a.getFieldValue("BUILT_IN_LED"),c=Blockly.Python.valueToCode(a,"STATE",Blockly.Python.ORDER_ATOMIC)||"LOW";Blockly.Python.reservePin(a,b,Blockly.Python.PinTypes.OUTPUT,"Set LED");Blockly.Python.addSetup("io_"+b,"pinMode("+b+", OUTPUT);",!1);return"digitalWrite("+b+", "+c+");\n"}; Blockly.Python.io_analogwrite=function(a){var b=Blockly.Python.valueToCode(a,"PIN",Blockly.Python.ORDER_ATOMIC)||"0",c=Blockly.Python.valueToCode(a,"ANALOGNUM",Blockly.Python.ORDER_ATOMIC)||"0";var d=/A[0-9]/g.test(b);var e="";d?(Blockly.Python.reservePin(a,b,Blockly.Python.PinTypes.OUTPUT,"Analogue Write"),Blockly.Python.addSetup("io_"+b,"pinMode("+b+", OUTPUT);",!1)):(Blockly.Python.addDeclaration("io_analogPinList","const int analogPIN[8]={A0,A1,A2,A3,A4,A5,A6,A7};"),Blockly.Python.addSetup("io_A0", "pinMode(A0, OUTPUT);"),Blockly.Python.addSetup("io_A1","pinMode(A1, OUTPUT);"),Blockly.Python.addSetup("io_A2","pinMode(A2, OUTPUT);"),Blockly.Python.addSetup("io_A3","pinMode(A3, OUTPUT);"),Blockly.Python.addSetup("io_A4","pinMode(A4, OUTPUT);"),Blockly.Python.addSetup("io_A5","pinMode(A5, OUTPUT);"),Blockly.Python.addSetup("io_A6","pinMode(A6, OUTPUT);"),Blockly.Python.addSetup("io_A7","pinMode(A7, OUTPUT);"),e="analogPIN["+b+"]");0>c||255");Blockly.Python.addInclude("Adafruit_NeoMatrix","#include ");Blockly.Python.addInclude("Adafruit_NeoPixel","#include ");var b=a.getFieldValue("neopixel_initpin"),c=a.getFieldValue("neopixel_initheight"),d=a.getFieldValue("neopixel_initwidth");a=a.getFieldValue("neopixel_initbright");Blockly.Python.addDeclaration("ledDeclA"+b,"#ifndef PSTR\n #define PSTR\n#endif\n", !1);Blockly.Python.addDeclaration("ledDeclB"+b,"#define\tPIN\t"+b,!1);Blockly.Python.addDeclaration("ledDeclC"+b,"Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(5,5,"+d+","+c+", PIN,NEO_TILE_TOP + NEO_TILE_LEFT + NEO_TILE_COLUMNS + NEO_TILE_PROGRESSIVE + NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE,NEO_GRB + NEO_KHZ800);");Blockly.Python.addSetup("ledSetup"+b,"matrix.begin();\n matrix.setBrightness("+a+");\n");globalBrightness=a;return""}; Blockly.Python.led_setrotation=function(a){return"matrix.setRotation("+a.getFieldValue("led_setrotation_option")+");\n"};Blockly.Python.led_setbright=function(a){return"matrix.setBrightness("+Blockly.Python.valueToCode(a,"BRIGHTNESS",Blockly.Python.ORDER_ATOMIC)+");\n"};Blockly.Python.led_set_width_height=function(a){var b=Blockly.Python.valueToCode(a,"WIDTH",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"HEIGHT",Blockly.Python.ORDER_ATOMIC);return[b+", "+a,Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.led_set_position=function(a){var b=Blockly.Python.valueToCode(a,"POSX",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"POSY",Blockly.Python.ORDER_ATOMIC);return[b+", "+a,Blockly.Python.ORDER_ATOMIC]};Blockly.Python.led_drawpixel=function(a){var b=Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC);b="#"==b[0]?hexToRgb(b):b;return"matrix.drawPixel("+Blockly.Python.valueToCode(a,"POS",Blockly.Python.ORDER_ATOMIC)+",matrix.Color"+b+");\n"}; Blockly.Python.led_drawrect=function(a){var b=Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC);b="#"==b[0]?hexToRgb(b):b;var c=Blockly.Python.valueToCode(a,"SIZE",Blockly.Python.ORDER_ATOMIC),d=a.getFieldValue("rect_type");a=Blockly.Python.valueToCode(a,"POS",Blockly.Python.ORDER_ATOMIC);return"matrix."+d+"Rect("+a+","+c+",matrix.Color"+b+");\n"}; Blockly.Python.led_drawline=function(a){var b=Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC);b="#"==b[0]?hexToRgb(b):b;Blockly.Python.valueToCode(a,"TYPE",Blockly.Python.ORDER_ATOMIC);var c=Blockly.Python.valueToCode(a,"POSA",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"POSB",Blockly.Python.ORDER_ATOMIC);return"matrix.drawLine("+c+","+a+",matrix.Color"+b+");\n"}; Blockly.Python.led_showall=function(a){return"matrix.show();\ndelayMicroseconds(500);\nmatrix.setBrightness("+globalBrightness+");\n"}; Blockly.Python.led_text=function(a){var b=Number(a.getFieldValue("x_val")),c=Number(a.getFieldValue("y_val")),d=hexToRgb(Blockly.Python.valueToCode(a,"text_color",Blockly.Python.ORDER_ATOMIC)),e=hexToRgb(Blockly.Python.valueToCode(a,"back_color",Blockly.Python.ORDER_ATOMIC));a=a.getFieldValue("text_size");return"matrix.setCursor("+b+", "+c+");\nmatrix.setTextColor(matrix.Color"+d+", matrix.Color"+e+");\nmatrix.setTextSize("+a+");\nmatrix.setTextWrap(false);\n"}; Blockly.Python.led_clear=function(a){Blockly.Python.addFunction("led_clear","void ledClear() {\n matrix.fillScreen(0);\n matrix.show();\n delay(1);\n}\n");return"ledClear();\n"}; Blockly.Python.led_scrolling_text=function(a){var b=a.getFieldValue("led_scrolling_speed");a=hexToRgb(Blockly.Python.valueToCode(a,"led_scrolling_color",Blockly.Python.ORDER_ATOMIC));Blockly.Python.addDeclarataddDion("led_scrolling_decl","int x = tiledMatrix.width() ;");return"matrix.setTextWrap(false);\nmatrix.setTextColor(matrix.Color"+a+");\nmatrix.setCursor(x, 0);\nint len = text.length()*6;\nlen *= (-1);\n//every word takes about 6 pixel wide\nif(--x < len) {\nx = matrix.width();\n}\nmatrix.show();\ndelay("+ b+");\n"}; Blockly.Python.led_pattern_5x5=function(a){Blockly.Python.addFunction("pattern_5x5","void setPattern(uint16_t patternMatrix[5][5]) {\n for (int row=0; row<5; row++) {\n for (int col=0; col<5; col++) {\n matrix.drawPixel(row, col, patternMatrix[col][row]);\n }\n }\n}\n");Blockly.Python.addDeclaration("pattern_5x5_dec","uint16_t pattern[5][5] =\n{\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), }\n};\n");for(var b= "",c=0;5>c;c++){for(var d=0;5>d;d++){var e="matrix.Color"+hexToRgb(a.getFieldValue(c+"_"+d));"matrix.Color(59, 85, 135)"===e&&(e="matrix.Color(0, 0, 0)");b+="pattern[4-"+c+"][4-"+d+"] = "+e+"; "}b+="\n"}return b+"setPattern(pattern);\n"}; Blockly.Python.led_drawWord_5x5=function(a){var b=Blockly.Python.valueToCode(a,"WORD",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC);a="#"==a[0]?hexToRgb(a):a;Blockly.Python.addInclude("myfont_5x5","#include ");Blockly.Python.addSetup("setTextWrap_false","matrix.setTextWrap(false);");Blockly.Python.addSetup("font_5x5","matrix.setFont(&MyFont5pt7b);\n");return"matrix.setTextColor(matrix.Color"+a+");\nmatrix.setCursor(0, 4);\nmatrix.print(F("+ b+"));\n"}; Blockly.Python.led_text_input=function(a){var b=a.getFieldValue("scroll"),c=a.getFieldValue("font"),d=Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_ATOMIC),e=/"/g.test(d);var f=Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC);f="#"==f[0]?hexToRgb(f):f;var g=Blockly.Python.valueToCode(a,"POS",Blockly.Python.ORDER_ATOMIC);a=parseInt(g.split(",")[0]);g=parseInt(g.split(",")[1]);f="matrix.setTextColor(matrix.Color"+f+");\n";Blockly.Python.addSetup("setTextWrap_false","matrix.setTextWrap(false);"); "1"==c?(Blockly.Python.addInclude("myfont_5x5","#include "),Blockly.Python.addSetup("myfont_setup","matrix.setFont(&MyFont5pt7b);\n"),g+=4,Blockly.Python.addDeclaration("pixelPerChar_5","int pixelPerChar = 5;")):"3"==c?(Blockly.Python.addInclude("FreeSansBold9pt7b","#include "),Blockly.Python.addSetup("FreeSansBold9pt7b","matrix.setFont(&FreeSansBold9pt7b);\n"),g+=12,Blockly.Python.addDeclaration("pixelPerChar_9","int pixelPerChar = 9;")):Blockly.Python.addDeclaration("pixelPerChar_5", "int pixelPerChar = 5;");"1"==b?(Blockly.Python.addDeclaration("scroll_"+a+"_"+g,"int scroll_"+a+"_"+g+" = matrix.width();"),Blockly.Python.addDeclaration("maxDisplacement_"+a+"_"+g,"int maxDisplacement_"+a+"_"+g+";"),f+="matrix.fillScreen(0);\nmatrix.setRotation(2);\nmatrix.setCursor(scroll_"+a+"_"+g+"+"+a+", "+g+");\n ",f=(e?f+("matrix.print(F("+d+"));\nmaxDisplacement_"+a+"_"+g+" = strlen("+d+")* pixelPerChar + matrix.width();\n"):f+("matrix.print("+d+");\nmaxDisplacement_"+a+"_"+g+" = "+d+".length()* pixelPerChar + matrix.width();\n"))+ ("if(--scroll_"+a+"_"+g+" < -maxDisplacement_"+a+"_"+g+") {\nscroll_"+a+"_"+g+" = matrix.width();\n}\n")):(f+="matrix.setCursor("+a+","+g+");\n",f=e?f+("matrix.print(F("+d+"));\n"):f+("matrix.print("+d+");\n"));return f}; Blockly.Python.led_draw_emotion=function(a){Blockly.Python.addFunction("pattern_5x5","void setPattern(uint16_t patternMatrix[5][5]) {\n for (int row=0; row<5; row++) {\n for (int col=0; col<5; col++) {\n matrix.drawPixel(row, col, patternMatrix[col][row]);\n }\n }\n}\n");Blockly.Python.addDeclaration("pattern_5x5_dec","uint16_t pattern[5][5] =\n{\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), }\n};\n"); var b=a.getFieldValue("face");a.updateImage_();a=Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC);a="#"==a[0]?hexToRgb(a):a;var c="";switch(b){case "1":c="pattern[0][0] = matrix.Color(0, 0, 0); pattern[0][1] = matrix.Color(0, 0, 0); pattern[0][2] = matrix.Color(0, 0, 0); pattern[0][3] = matrix.Color(0, 0, 0); pattern[0][4] = matrix.Color(0, 0, 0);\npattern[1][0] = matrix.Color(0, 0, 0); pattern[1][1] = matrix.Color"+a+"; pattern[1][2] = matrix.Color(0, 0, 0); pattern[1][3] = matrix.Color"+ a+"; pattern[1][4] = matrix.Color(0, 0, 0);\npattern[2][0] = matrix.Color(0, 0, 0); pattern[2][1] = matrix.Color(0, 0, 0); pattern[2][2] = matrix.Color(0, 0, 0); pattern[2][3] = matrix.Color(0, 0, 0); pattern[2][4] = matrix.Color(0, 0, 0);\npattern[3][0] = matrix.Color"+a+"; pattern[3][1] = matrix.Color(0, 0, 0); pattern[3][2] = matrix.Color(0, 0, 0); pattern[3][3] = matrix.Color(0, 0, 0); pattern[3][4] = matrix.Color"+a+";\npattern[4][0] = matrix.Color(0, 0, 0); pattern[4][1] = matrix.Color"+a+"; pattern[4][2] = matrix.Color"+ a+"; pattern[4][3] = matrix.Color"+a+"; pattern[4][4] = matrix.Color(0, 0, 0);\nsetPattern(pattern);\n";break;case "2":c="pattern[0][0] = matrix.Color(0, 0, 0); pattern[0][1] = matrix.Color(0, 0, 0); pattern[0][2] = matrix.Color(0, 0, 0); pattern[0][3] = matrix.Color(0, 0, 0); pattern[0][4] = matrix.Color(0, 0, 0);\npattern[1][0] = matrix.Color"+a+"; pattern[1][1] = matrix.Color"+a+"; pattern[1][2] = matrix.Color(0, 0, 0); pattern[1][3] = matrix.Color"+a+"; pattern[1][4] = matrix.Color"+a+";\npattern[2][0] = matrix.Color(0, 0, 0); pattern[2][1] = matrix.Color(0, 0, 0); pattern[2][2] = matrix.Color(0, 0, 0); pattern[2][3] = matrix.Color(0, 0, 0); pattern[2][4] = matrix.Color(0, 0, 0);\npattern[3][0] = matrix.Color(0, 0, 0); pattern[3][1] = matrix.Color"+ a+"; pattern[3][2] = matrix.Color"+a+"; pattern[3][3] = matrix.Color"+a+"; pattern[3][4] = matrix.Color(0, 0, 0);\npattern[4][0] = matrix.Color(0, 0, 0); pattern[4][1] = matrix.Color(0, 0, 0); pattern[4][2] = matrix.Color(0, 0, 0); pattern[4][3] = matrix.Color(0, 0, 0); pattern[4][4] = matrix.Color(0, 0, 0);\nsetPattern(pattern);\n";break;case "3":c="pattern[0][0] = matrix.Color(0, 0, 0); pattern[0][1] = matrix.Color(0, 0, 0); pattern[0][2] = matrix.Color(0, 0, 0); pattern[0][3] = matrix.Color(0, 0, 0); pattern[0][4] = matrix.Color(0, 0, 0);\npattern[1][0] = matrix.Color(0, 0, 0); pattern[1][1] = matrix.Color"+ a+"; pattern[1][2] = matrix.Color(0, 0, 0); pattern[1][3] = matrix.Color"+a+"; pattern[1][4] = matrix.Color(0, 0, 0);\npattern[2][0] = matrix.Color(0, 0, 0); pattern[2][1] = matrix.Color(0, 0, 0); pattern[2][2] = matrix.Color(0, 0, 0); pattern[2][3] = matrix.Color(0, 0, 0); pattern[2][4] = matrix.Color(0, 0, 0);\npattern[3][0] = matrix.Color(0, 0, 0); pattern[3][1] = matrix.Color"+a+"; pattern[3][2] = matrix.Color"+a+"; pattern[3][3] = matrix.Color"+a+"; pattern[3][4] = matrix.Color(0, 0, 0);\npattern[4][0] = matrix.Color"+ a+"; pattern[4][1] = matrix.Color(0, 0, 0); pattern[4][2] = matrix.Color(0, 0, 0); pattern[4][3] = matrix.Color(0, 0, 0); pattern[4][4] = matrix.Color"+a+";\nsetPattern(pattern);\n"}return c};Blockly.Python.led_draw_strip=function(a){var b=Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC);b="#"==b[0]?hexToRgb(b):b;a=Blockly.Python.valueToCode(a,"LOC",Blockly.Python.ORDER_ATOMIC);return"matrix.drawPixel("+(a+" % 5 , "+a+" / 5,matrix.Color")+b+");\n"}; Blockly.Python.led_set_color=function(a){return[a.getFieldValue("COLOR"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.led_set_colorRGB=function(a){var b=Blockly.Python.valueToCode(a,"RED_VAL",Blockly.Python.ORDER_ATOMIC),c=Blockly.Python.valueToCode(a,"GREEN_VAL",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"BLUE_VAL",Blockly.Python.ORDER_ATOMIC);return["("+b+","+c+","+a+")",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.lists={};Blockly.Python.lists_create_with=function(a){a=Array(this.itemCount_);for(var b=0;b",GTE:">="}[a.getFieldValue("OP")],c="=="==b||"!="==b?Blockly.Python.ORDER_EQUALITY:Blockly.Python.ORDER_RELATIONAL,d=Blockly.Python.valueToCode(a,"A",c)||"0";a=Blockly.Python.valueToCode(a,"B",c)||"0";return[d+" "+b+" "+a,c]}; Blockly.Python.logic_operation=function(a){var b="AND"==a.getFieldValue("OP")?"&&":"||",c="&&"==b?Blockly.Python.ORDER_LOGICAL_AND:Blockly.Python.ORDER_LOGICAL_OR,d=Blockly.Python.valueToCode(a,"A",c)||"false";a=Blockly.Python.valueToCode(a,"B",c)||"false";if(d||a){var e="&&"==b?"true":"false";d||(d=e);a||(a=e)}else a=d="false";return[d+" "+b+" "+a,c]};Blockly.Python.logic_negate=function(a){var b=Blockly.Python.ORDER_UNARY_PREFIX;return["!"+(Blockly.Python.valueToCode(a,"BOOL",b)||"false"),b]}; Blockly.Python.logic_boolean=function(a){return["TRUE"==a.getFieldValue("BOOL")?"true":"false",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.logic_null=function(a){return["NULL",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.logic_ternary=function(a){var b=Blockly.Python.valueToCode(a,"IF",Blockly.Python.ORDER_CONDITIONAL)||"false",c=Blockly.Python.valueToCode(a,"THEN",Blockly.Python.ORDER_CONDITIONAL)||"null";a=Blockly.Python.valueToCode(a,"ELSE",Blockly.Python.ORDER_CONDITIONAL)||"null";return[b+" ? "+c+" : "+a,Blockly.Python.ORDER_CONDITIONAL]};Blockly.Python.loops={};Blockly.Python.controls_repeat=function(a){var b=Number(a.getFieldValue("TIMES")),c=Blockly.Python.statementToCode(a,"DO");c=Blockly.Python.addLoopTrap(c,a.id);a=Blockly.Python.variableDB_.getDistinctName("count",Blockly.Variables.NAME_TYPE);return"for (int "+a+" = 0; "+a+" < "+b+"; "+a+"++) {\n"+c+"}\n"}; Blockly.Python.controls_repeat_ext=function(a){var b=Blockly.Python.valueToCode(a,"TIMES",Blockly.Python.ORDER_ADDITIVE)||"0",c=Blockly.Python.statementToCode(a,"DO");c=Blockly.Python.addLoopTrap(c,a.id);a="";var d=Blockly.Python.variableDB_.getDistinctName("count",Blockly.Variables.NAME_TYPE),e=b;b.match(/^\w+$/)||Blockly.isNumber(b)||(e=Blockly.Python.variableDB_.getDistinctName("repeat_end",Blockly.Variables.NAME_TYPE),a+="int "+e+" = "+b+";\n");return a+("for (int "+d+" = 0; "+d+" < "+e+"; "+ d+"++) {\n"+c+"}\n")};Blockly.Python.controls_whileUntil=function(a){var b="UNTIL"==a.getFieldValue("MODE"),c=Blockly.Python.valueToCode(a,"BOOL",b?Blockly.Python.ORDER_LOGICAL_OR:Blockly.Python.ORDER_NONE)||"false",d=Blockly.Python.statementToCode(a,"DO");d=Blockly.Python.addLoopTrap(d,a.id);b&&(c.match(/^\w+$/)||(c="("+c+")"),c="!"+c);return"while ("+c+") {\n"+d+"}\n"}; Blockly.Python.controls_for=function(a){var b=Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),c=Blockly.Python.valueToCode(a,"FROM",Blockly.Python.ORDER_ASSIGNMENT)||"0",d=Blockly.Python.valueToCode(a,"TO",Blockly.Python.ORDER_ASSIGNMENT)||"0",e=Blockly.Python.valueToCode(a,"BY",Blockly.Python.ORDER_ASSIGNMENT)||"1",f=Blockly.Python.statementToCode(a,"DO");f=Blockly.Python.addLoopTrap(f,a.id);if(Blockly.isNumber(c)&&Blockly.isNumber(d)&&Blockly.isNumber(e)){var g= parseFloat(c)<=parseFloat(d);a="for ("+b+" = "+c+"; "+b+(g?" <= ":" >= ")+d+"; "+b;b=Math.abs(parseFloat(e));a=(1==b?a+(g?"++":"--"):a+((g?" += ":" -= ")+b))+(") {\n"+f+"}\n")}else a="",g=c,c.match(/^\w+$/)||Blockly.isNumber(c)||(g=Blockly.Python.variableDB_.getDistinctName(b+"_start",Blockly.Variables.NAME_TYPE),a+="int "+g+" = "+c+";\n"),c=d,d.match(/^\w+$/)||Blockly.isNumber(d)||(c=Blockly.Python.variableDB_.getDistinctName(b+"_end",Blockly.Variables.NAME_TYPE),a+="int "+c+" = "+d+";\n"),d=Blockly.Python.variableDB_.getDistinctName(b+ "_inc",Blockly.Variables.NAME_TYPE),a+="int "+d+" = ",a=Blockly.isNumber(e)?a+(Math.abs(e)+";\n"):a+("abs("+e+");\n"),a=a+("if ("+g+" > "+c+") {\n")+(Blockly.Python.INDENT+d+" = -"+d+";\n"),a+="}\n",a+="for ("+b+" = "+g+";\n "+d+" >= 0 ? "+b+" <= "+c+" : "+b+" >= "+c+";\n "+b+" += "+d+") {\n"+f+"}\n";return a};Blockly.Python.controls_forEach=Blockly.Python.noGeneratorCodeLine; Blockly.Python.controls_flow_statements=function(a){switch(a.getFieldValue("FLOW")){case "BREAK":return"break;\n";case "CONTINUE":return"continue;\n"}throw"Unknown flow statement.";};Blockly.Python.mainwifi={};Blockly.Python.mainwifi_setup=function(a){Blockly.Python.addSetup("serial_9600","Serial.begin(9600);");return""}; Blockly.Python.mainwifi_sendMsg=function(a){Blockly.Python.addDeclaration("wifi_dataTransfer_checkbit","#define SOP '<'\n#define EOP '>'\n");a=Blockly.Python.variableDB_.getName(a.getFieldValue("dataVar"),Blockly.Variables.NAME_TYPE);var b="sizeof("+a+")/sizeof("+a+"[0])",c=b+"+2";return"unsigned char DataOut_["+c+"];\nDataOut_[0]= SOP;\nDataOut_["+b+"+1]= EOP;\nfor (int i=0; i<"+b+";i++) {\n DataOut_[i+1]="+a+"[i];\n}\nSerial1.write(DataOut_, "+c+");\n"}; Blockly.Python.mainwifi_receiveMsg=function(a){Blockly.Python.addDeclaration("wifi_dataTransfer_checkbit","#define SOP '<'\n#define EOP '>'\n");Blockly.Python.addDeclaration("wifi_dataTransfer_MsgReceiveStatus","bool started = false;\nbool ended = false;\nint index_i;\n");a=Blockly.Python.variableDB_.getName(a.getFieldValue("dataVar"),Blockly.Variables.NAME_TYPE);Blockly.Python.addFunction("mainwifi_dataIn_function","int handleDataIn() {\n while (Serial1.available() > 0) {\n int inChar = Serial1.read();\n if(inChar == SOP) {\n index_i = 0;\n started = true;\n ended = false;\n } else if(inChar == EOP) {\n ended = true;\n break;\n }else if((index_i < "+ ("sizeof("+a+")/sizeof("+a+"[0])"||1)+")&&started&&(!ended)) {\n "+a+"[index_i] = inChar;\n index_i++;\n }\n }\n if(started && ended) {\n return 1;\n } else {\n return 0;\n }\n}\n");return"boolean receiveMsgsuccess_ = handleDataIn();\n"};Blockly.Python.mainwifi_receiveMsg_isSuccessed=function(a){return["receiveMsgsuccess_",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.MainEasymode_transfer_send=function(a){a=Blockly.Python.variableDB_.getName(a.getFieldValue("DATAMAIN"),Blockly.Variables.NAME_TYPE);Blockly.Python.addSetup("serial1","Serial1.begin(9600);");Blockly.Python.addDeclaration("wifi_dataTransfer_checkbit","#define SOP '<'\n#define EOP '>'\n");var b="sizeof("+a+")/sizeof("+a+"[0])",c=b+"+2";return"unsigned char DataOut_["+c+"];\nDataOut_[0]= SOP;\nDataOut_["+b+"+1]= EOP;\nfor (int i=0; i<"+b+";i++) {\n DataOut_[i+1]="+a+"[i];\n}\nSerial1.write(DataOut_, "+ c+");\n"}; Blockly.Python.MainEasymode_transfer_receive=function(a){a=Blockly.Python.variableDB_.getName(a.getFieldValue("DATAMAIN"),Blockly.Variables.NAME_TYPE);Blockly.Python.addSetup("serial1","Serial1.begin(9600);");Blockly.Python.addDeclaration("wifi_dataTransfer_checkbit","#define SOP '<'\n#define EOP '>'\n");Blockly.Python.addDeclaration("wifi_dataTransfer_MsgReceiveStatus","bool started = false;\nbool ended = false;\nint index_i;\n");Blockly.Python.addFunction("mainwifi_dataIn_function","int handleDataIn() {\n while (Serial1.available() > 0) {\n int inChar = Serial1.read();\n if(inChar == SOP) {\n index_i = 0;\n started = true;\n ended = false;\n } else if(inChar == EOP) {\n ended = true;\n break;\n }else if((index_i < "+("sizeof("+ a+")/sizeof("+a+"[0])"||1)+")&&started&&(!ended)) {\n "+a+"[index_i] = inChar;\n index_i++;\n }\n }\n if(started && ended) {\n return 1;\n } else {\n return 0;\n }\n}\n");return"boolean receiveMsgsuccess_ = handleDataIn();\n"}; Blockly.Python.MainEasymode_transfer2_send_old=function(a){a=a.getFieldValue("DATAMAIN");for(var b="int "+a+"["+this.itemCount_+"] = {0",c=1;c'\n");b="sizeof("+a+")/sizeof("+a+"[0])";c=b+"+2";for(var d="",e,f=0;f'\n");Blockly.Python.addDeclaration("wifi_dataTransfer_MsgReceiveStatus","bool started = false;\nbool ended = false;\nint index_i;\n"); Blockly.Python.addFunction("mainwifi_dataIn_function","int handleDataIn() {\n while (Serial1.available() > 0) {\n int inChar = Serial1.read();\n if(inChar == SOP) {\n index_i = 0;\n started = true;\n ended = false;\n } else if(inChar == EOP) {\n ended = true;\n break;\n }else if((index_i < "+("sizeof("+b+")/sizeof("+b+"[0])"||1)+")&&started&&(!ended)) {\n "+b+"[index_i] = inChar;\n index_i++;\n }\n }\n delay(10);\n if(started && ended) {\n return 1;\n } else {\n return 0;\n }\n}\n"); return'boolean receiveMsgsuccess_ = handleDataIn();\nif (!receiveMsgsuccess_) {\n Serial.println("Error: Fail to receive data!");\n return;\n}\n'};Blockly.Python.MainEasymode_transfer2_receive_getValue_old=function(a){var b=a.getFieldValue("DATAMAIN")||"_main_transfer";a=a.getFieldValue("INDEX");return[""+b+"["+a+"]",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.MainEasymode_transfer2_send=function(a){Blockly.Python.addDeclaration("Serial_sendState","int serialSendState = 0;");Blockly.Python.addSetup("serial1","Serial1.begin(9600);");Blockly.Python.addFunction("SerialSendData","void serialSendData() {\n int serialDataLength = serialDataPackage().length() + 1;\n char serialDataBuf[serialDataLength];\n serialDataPackage().toCharArray(serialDataBuf, serialDataLength);\n if ( serialSendState == 0 ) {\n Serial1.write(serialDataBuf);\n }\n if ( (millis() / 100) % 4 == 3 && serialSendState == 0) {\n Serial1.write(serialDataBuf);\n serialSendState = 1;\n } else if ( (millis() / 100) % 4 == 1) {\n serialSendState = 0;\n }\n}\n"); for(var b='String serialDataPackage() { \n String data = "";\n data += "SOF";\n',c=0;c 0) {\n serialDataReceived = Serial1.readStringUntil("\\r\\n");\n }\n if (getSerialDataValue(serialDataReceived, \'|\', 0) == "SOF") {\n return 1;\n } else {\n return 0;\n }\n}\n'); Blockly.Python.addFunction("getSerialDataValue",'String getSerialDataValue(String data, char separator, int index)\n{\n int found = 0;\n int strIndex[] = {0, -1};\n int maxIndex = data.length() - 1;\n for (int i = 0; i <= maxIndex && found <= index; i++) {\n if (data.charAt(i) == separator || i == maxIndex) {\n found++;\n strIndex[0] = strIndex[1] + 1;\n strIndex[1] = (i == maxIndex) ? i + 1 : i;\n }\n }\n return found > index ? data.substring(strIndex[0], strIndex[1]) : "";\n}\n'); return'boolean serialReceiveCheck_ = serialDataFilter();\nif (!serialReceiveCheck_) {\n Serial.println("Error receiving data from WiFi Module.");\n return;\n }\n'};Blockly.Python.MainEasymode_transfer2_receive_getValue=function(a){var b=parseInt(a.getFieldValue("INDEX"))+1;a=a.getFieldValue("TYPE");return["getSerialDataValue(serialDataReceived, '|', "+b+")"+a,Blockly.Python.ORDER_ATOMIC]};Blockly.Python.map={};Blockly.Python.base_map=function(a){var b=Blockly.Python.valueToCode(a,"NUM",Blockly.Python.ORDER_NONE)||"0";a=Blockly.Python.valueToCode(a,"DMAX",Blockly.Python.ORDER_ATOMIC)||"0";return["map("+b+", 0, 1024, 0, "+a+")",Blockly.Python.ORDER_NONE]};Blockly.Python.math={};Blockly.Python.math_number=function(a){a=parseFloat(a.getFieldValue("NUM"));Infinity==a?a="INFINITY":-Infinity==a&&(a="-INFINITY");return[a,Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.math_arithmetic=function(a){var b={ADD:[" + ",Blockly.Python.ORDER_ADDITIVE],MINUS:[" - ",Blockly.Python.ORDER_ADDITIVE],MULTIPLY:[" * ",Blockly.Python.ORDER_MULTIPLICATIVE],DIVIDE:[" / ",Blockly.Python.ORDER_MULTIPLICATIVE],POWER:[null,Blockly.Python.ORDER_NONE]}[a.getFieldValue("OP")],c=b[0];b=b[1];var d=Blockly.Python.valueToCode(a,"A",b)||"0";a=Blockly.Python.valueToCode(a,"B",b)||"0";return c?[d+c+a,b]:["Math.pow("+d+", "+a+")",Blockly.Python.ORDER_UNARY_POSTFIX]}; Blockly.Python.math_single=function(a){var b=a.getFieldValue("OP");if("NEG"==b)return a=Blockly.Python.valueToCode(a,"NUM",Blockly.Python.ORDER_UNARY_PREFIX)||"0","-"==a[0]&&(a=" "+a),["-"+a,Blockly.Python.ORDER_UNARY_PREFIX];a="ABS"==b||"ROUND"==b.substring(0,5)?Blockly.Python.valueToCode(a,"NUM",Blockly.Python.ORDER_UNARY_POSTFIX)||"0":"SIN"==b||"COS"==b||"TAN"==b?Blockly.Python.valueToCode(a,"NUM",Blockly.Python.ORDER_MULTIPLICATIVE)||"0":Blockly.Python.valueToCode(a,"NUM",Blockly.Python.ORDER_NONE)|| "0";switch(b){case "ABS":var c="abs("+a+")";break;case "ROOT":c="sqrt("+a+")";break;case "LN":c="log("+a+")";break;case "EXP":c="exp("+a+")";break;case "POW10":c="pow(10,"+a+")";break;case "ROUND":c="round("+a+")";break;case "ROUNDUP":c="ceil("+a+")";break;case "ROUNDDOWN":c="floor("+a+")";break;case "SIN":c="sin("+a+" / 180 * Math.PI)";break;case "COS":c="cos("+a+" / 180 * Math.PI)";break;case "TAN":c="tan("+a+" / 180 * Math.PI)"}if(c)return[c,Blockly.Python.ORDER_UNARY_POSTFIX];switch(b){case "LOG10":c= "log("+a+") / log(10)";break;case "ASIN":c="asin("+a+") / M_PI * 180";break;case "ACOS":c="acos("+a+") / M_PI * 180";break;case "ATAN":c="atan("+a+") / M_PI * 180";break;default:throw"Unknown math operator: "+b;}return[c,Blockly.Python.ORDER_MULTIPLICATIVE]}; Blockly.Python.math_constant=function(a){return{PI:["M_PI",Blockly.Python.ORDER_UNARY_POSTFIX],E:["M_E",Blockly.Python.ORDER_UNARY_POSTFIX],GOLDEN_RATIO:["(1 + sqrt(5)) / 2",Blockly.Python.ORDER_MULTIPLICATIVE],SQRT2:["M_SQRT2",Blockly.Python.ORDER_UNARY_POSTFIX],SQRT1_2:["M_SQRT1_2",Blockly.Python.ORDER_UNARY_POSTFIX],INFINITY:["INFINITY",Blockly.Python.ORDER_ATOMIC]}[a.getFieldValue("CONSTANT")]}; Blockly.Python.math_number_property=function(a){var b=Blockly.Python.valueToCode(a,"NUMBER_TO_CHECK",Blockly.Python.ORDER_MULTIPLICATIVE)||"0",c=a.getFieldValue("PROPERTY");if("PRIME"==c)return a=Blockly.Python.addFunction("mathIsPrime",["boolean "+Blockly.Python.DEF_FUNC_NAME+"(int n) {"," // https://en.wikipedia.org/wiki/Primality_test#Naive_methods\n if (n == 2 || n == 3) {\n return true;\n }\n // False if n is NaN, negative, is 1.\n // And false if n is divisible by 2 or 3.\n if (isnan(n) || (n <= 1) || (n == 1) || (n % 2 == 0) || (n % 3 == 0)) {\n return false;\n }\n // Check all the numbers of form 6k +/- 1, up to sqrt(n).\n for (int x = 6; x <= sqrt(n) + 1; x += 6) {\n if (n % (x - 1) == 0 || n % (x + 1) == 0) {\n return false;\n }\n }\n return true;\n}"].join("\n")), Blockly.Python.addInclude("math","#include "),[a+"("+b+")",Blockly.Python.ORDER_UNARY_POSTFIX];switch(c){case "EVEN":var d=b+" % 2 == 0";break;case "ODD":d=b+" % 2 == 1";break;case "WHOLE":Blockly.Python.addInclude("math","#include ");d="(floor("+b+") == "+b+")";break;case "POSITIVE":d=b+" > 0";break;case "NEGATIVE":d=b+" < 0";break;case "DIVISIBLE_BY":a=Blockly.Python.valueToCode(a,"DIVISOR",Blockly.Python.ORDER_MULTIPLICATIVE)||"0",d=b+" % "+a+" == 0"}return[d,Blockly.Python.ORDER_EQUALITY]}; Blockly.Python.math_change=function(a){var b=Blockly.Python.valueToCode(a,"DELTA",Blockly.Python.ORDER_ADDITIVE)||"0";return Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE)+" += "+b+";\n"};Blockly.Python.math_round=Blockly.Python.math_single;Blockly.Python.math_trig=Blockly.Python.math_single;Blockly.Python.math_on_list=Blockly.Python.noGeneratorCodeInline; Blockly.Python.math_modulo=function(a){var b=Blockly.Python.valueToCode(a,"DIVIDEND",Blockly.Python.ORDER_MULTIPLICATIVE)||"0";a=Blockly.Python.valueToCode(a,"DIVISOR",Blockly.Python.ORDER_MULTIPLICATIVE)||"0";return[b+" % "+a,Blockly.Python.ORDER_MULTIPLICATIVE]}; Blockly.Python.math_constrain=function(a){var b=Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_NONE)||"0",c=Blockly.Python.valueToCode(a,"LOW",Blockly.Python.ORDER_NONE)||"0";a=Blockly.Python.valueToCode(a,"HIGH",Blockly.Python.ORDER_NONE)||"0";return["("+b+" < "+c+" ? "+c+" : ( "+b+" > "+a+" ? "+a+" : "+b+"))",Blockly.Python.ORDER_UNARY_POSTFIX]}; Blockly.Python.math_random_int=function(a){var b=Blockly.Python.valueToCode(a,"FROM",Blockly.Python.ORDER_NONE)||"0";a=Blockly.Python.valueToCode(a,"TO",Blockly.Python.ORDER_NONE)||"0";var c=Blockly.Python.variableDB_.getDistinctName("math_random_int",Blockly.Generator.NAME_TYPE);Blockly.Python.math_random_int.random_function=c;return[Blockly.Python.addFunction("mathRandomInt",["int "+Blockly.Python.DEF_FUNC_NAME+"(int min, int max) {"," if (min > max) {\n // Swap min and max to ensure min is smaller.\n int temp = min;\n min = max;\n max = temp;\n }\n return min + (rand() % (max - min + 1));\n}"].join("\n"))+ "("+b+", "+a+")",Blockly.Python.ORDER_UNARY_POSTFIX]};Blockly.Python.math_random_float=function(a){return["(rand() / RAND_MAX)",Blockly.Python.ORDER_UNARY_POSTFIX]};Blockly.Python.motion={}; Blockly.Python.motion_setup=function(a){Blockly.Python.addInclude("motion_include",'#include "I2Cdev.h"\n#include "MPU6050_6Axis_MotionApps20.h"\n#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE\n#include "Wire.h"\n#endif\n');Blockly.Python.addDeclaration("motion_declaration","MPU6050 mpu;\n\n#define _INTERRUPT_PIN 2\n#define _LED_PIN 13\nbool _blinkState = false;\n\nbool dmpReady = false; // set true if DMP init was successful\nuint8_t mpuIntStatus; // holds actual interrupt status byte from MPU\nuint8_t devStatus; // return status after each device operation (0 = success, !0 = error)\nuint16_t packetSize; // expected DMP packet size (default is 42 bytes)\nuint16_t fifoCount; // count of all bytes currently in FIFO\nuint8_t fifoBuffer[64]; // FIFO storage buffer\n\nQuaternion q; // [w, x, y, z] quaternion container\nVectorInt16 aa; // [x, y, z] accel sensor measurements\nVectorInt16 aaReal; // [x, y, z] gravity-free accel sensor measurements\nVectorFloat gravity; // [x, y, z] gravity vector\nfloat ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector\n\nvolatile bool mpuInterrupt = false; // indicates whether MPU interrupt pin has gone high\n\nfloat _motionGetYaw, _motionGetPitch, _motionGetRoll;\nint _directionState = 0;\nfloat _directionValue = 0.00;\nvoid dmpDataReady() {\nmpuInterrupt = true;\n}\n");Blockly.Python.addFunction("motion_SetupFunc", 'void _motionSensorSetup() {\n#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE\nWire.begin();\nWire.setClock(400000);\n#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE\nFastwire::setup(400, true);\n#endif\nSerial.begin(115200);\n// while (!Serial);\nSerial.println(F("Initializing I2C devices..."));\nmpu.initialize();\npinMode(_INTERRUPT_PIN, INPUT);\nSerial.println(F("Testing device connections..."));\nSerial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));\nSerial.println("Waiting for calibrating... 2s");\ndelay(1000);\nSerial.println("Waiting for calibrating... 1s");\ndelay(1000);\nSerial.println(F("Initializing DMP..."));\ndevStatus = mpu.dmpInitialize();\nmpu.setXGyroOffset(220);\nmpu.setYGyroOffset(76);\nmpu.setZGyroOffset(-85);\nmpu.setZAccelOffset(1788);\nif (devStatus == 0) {\nmpu.CalibrateAccel(6);\nmpu.CalibrateGyro(6);\nmpu.PrintActiveOffsets();\nSerial.println(F("Enabling DMP..."));\nmpu.setDMPEnabled(true);\nSerial.print(F("Enabling interrupt detection (Arduino external interrupt "));\nSerial.print(digitalPinToInterrupt(_INTERRUPT_PIN));\nSerial.println(F(")..."));\nattachInterrupt(digitalPinToInterrupt(_INTERRUPT_PIN), dmpDataReady, RISING);\nmpuIntStatus = mpu.getIntStatus();\nSerial.println(F("DMP ready! Waiting for first interrupt..."));\ndmpReady = true;\npacketSize = mpu.dmpGetFIFOPacketSize();\n} else {\nSerial.print(F("DMP Initialization failed (code "));\nSerial.print(devStatus);\nSerial.println(F(")"));\n}\npinMode(_LED_PIN, OUTPUT);\n}\n'); Blockly.Python.addFunction("motion_LoopFunc",'void _motionSensorMain() {\nif (!dmpReady) return;\nwhile (!mpuInterrupt && fifoCount < packetSize) {\nif (mpuInterrupt && fifoCount < packetSize) {\nfifoCount = mpu.getFIFOCount();\n}\n}\nmpuInterrupt = false;\nmpuIntStatus = mpu.getIntStatus();\nfifoCount = mpu.getFIFOCount();\nif (fifoCount < packetSize) {\n}\nelse if ((mpuIntStatus & _BV(MPU6050_INTERRUPT_FIFO_OFLOW_BIT)) || fifoCount >= 1024) {\n mpu.resetFIFO();\nSerial.println(F("FIFO overflow!"));\n} else if (mpuIntStatus & _BV(MPU6050_INTERRUPT_DMP_INT_BIT)) {\nwhile (fifoCount >= packetSize) {\nmpu.getFIFOBytes(fifoBuffer, packetSize);\nfifoCount -= packetSize;\n}\nmpu.dmpGetQuaternion(&q, fifoBuffer);\nmpu.dmpGetGravity(&gravity, &q);\nmpu.dmpGetYawPitchRoll(ypr, &q, &gravity);\n_motionGetYaw = ypr[0] * 180 / M_PI;\n_motionGetPitch = ypr[1] * 180 / M_PI;\n_motionGetRoll = ypr[2] * 180 / M_PI;\nmpu.dmpGetQuaternion(&q, fifoBuffer);\nmpu.dmpGetAccel(&aa, fifoBuffer);\nmpu.dmpGetGravity(&gravity, &q);\nmpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);\n_blinkState = !_blinkState;\ndigitalWrite(_LED_PIN, _blinkState);\n}\n}\n'); Blockly.Python.addSetup("motion_setup","_motionSensorSetup();\n");return"_motionSensorMain();\n"};Blockly.Python.motion_onshake=function(a){Blockly.Python.addFunction("onShake_function","boolean _motionOnShake() {\nif (aaReal.x < -5000 || aaReal.x > 5000 || aaReal.y < -5000 || aaReal.y > 5000 || aaReal.z < -5000 || aaReal.z > 5000) {\nreturn true;\n} else {\nreturn false;\n}\n}\n");return["_motionOnShake()",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.motion_onDirection=function(a){a=a.getFieldValue("DIRECTION");Blockly.Python.addFunction("onDirection_function","int _motionOnTilting(int direction) {\n _directionState = 0;\n switch (direction) {\n case 1:\n if (ypr[2] * 180 / M_PI < -20) {\n _directionState = 1;\n }\n break;\n case 2:\n if (ypr[2] * 180 / M_PI > 20) {\n _directionState = 1;\n }\n break;\n case 3:\n if (ypr[1] * 180 / M_PI < -20) {\n _directionState = 1;\n }\n break;\n case 4:\n if (ypr[1] * 180 / M_PI > 20) {\n _directionState = 1;\n }\n break;\n case 5:\n if (ypr[0] * 180 / M_PI +180 - _directionValue > 0) {\n _directionState = 1;\n }\n break;\n case 6:\n if (ypr[0] * 180 / M_PI +180 - _directionValue < 0) {\n _directionState = 1;\n }\n break;\n default:\n break;\n }\n _directionValue = ypr[0] * 180 / M_PI +180;\n return _directionState;\n}\n"); switch(a){case "left":var b=1;break;case "right":b=2;break;case "front":b=3;break;case "back":b=4;break;case "clockwise":b=5;break;case "counterClockwise":b=6}return["_motionOnTilting("+b+")",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.motion_getRotation_ypr=function(a){return["ypr["+a.getFieldValue("Rotation")+"] * 180 / M_PI",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.motion_getAcceleration=function(a){return["aaReal."+a.getFieldValue("Acceleration"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.motor={}; Blockly.Python.motor_setup=function(){Blockly.Python.addDeclaration("STBY_define","int STBY = A5;");Blockly.Python.addDeclaration("motor_A_define","// Motor A Definition\nint PWMA = 5; // Speed control\nint AIN1 = 9; // Direction\nint AIN2 = 10; // Direction");Blockly.Python.addDeclaration("motor_B_define","// Motor B Definition\nint PWMB = 6; // Speed control\nint BIN1 = 4; // Direction\nint BIN2 = 8; // Direction\n");Blockly.Python.addSetup("stby_setup","pinMode(STBY, OUTPUT);");Blockly.Python.addSetup("motor_A_setup", "// Motor A Setup\n pinMode(PWMA, OUTPUT);\n pinMode(AIN1, OUTPUT);\n pinMode(AIN2, OUTPUT);");Blockly.Python.addSetup("motor_B_setup","// Motor B Setup\n pinMode(PWMB, OUTPUT);\n pinMode(BIN1, OUTPUT);\n pinMode(BIN2, OUTPUT);");Blockly.Python.addFunction("motor_move_function","void move(int motor, int speed, int direction) {\n //Move specific motor at speed and direction\n //motor: 0 for B 1 for A\n //speed: 0 is off, and 255 is full speed\n //direction: 0 clockwise, 1 counter-clockwise\n digitalWrite(STBY, HIGH); //disable standby\n boolean inPin1 = LOW;\n boolean inPin2 = HIGH;\n if (direction == 1) {\n inPin1 = HIGH;\n inPin2 = LOW;\n }\n if (motor == 1) {\n digitalWrite(AIN1, inPin1);\n digitalWrite(AIN2, inPin2);\n analogWrite(PWMA, speed);\n } else {\n digitalWrite(BIN1, inPin1);\n digitalWrite(BIN2, inPin2);\n analogWrite(PWMB, speed);\n }\n}"); Blockly.Python.addFunction("motor_stop_function","void stop() {\n //enable standby\n digitalWrite(STBY, LOW);\n}");return""};Blockly.Python.motor_speed=function(a){return[a.getFieldValue("SPEED"),Blockly.Python.ORDER_NONE]};Blockly.Python.motorA_move_clockwise=function(a){var b=a.getFieldValue("MOTOR"),c=Blockly.Python.valueToCode(a,"SPEED",Blockly.Python.ORDER_ATOMIC);a=a.getFieldValue("DIRECTION");return"move("+b+","+c+","+a+");\n"}; Blockly.Python.motorA_move_anticlockwise=function(a){var b=a.getFieldValue("MOTOR"),c=Blockly.Python.valueToCode(a,"SPEED",Blockly.Python.ORDER_ATOMIC);a=a.getFieldValue("DIRECTION");return"move("+b+","+c+","+a+");\n"};Blockly.Python.motorB_move_clockwise=function(a){var b=a.getFieldValue("MOTOR"),c=Blockly.Python.valueToCode(a,"SPEED",Blockly.Python.ORDER_ATOMIC);a=a.getFieldValue("DIRECTION");return"move("+b+","+c+","+a+");\n"}; Blockly.Python.motorB_move_anticlockwise=function(a){var b=a.getFieldValue("MOTOR"),c=Blockly.Python.valueToCode(a,"SPEED",Blockly.Python.ORDER_ATOMIC);a=a.getFieldValue("DIRECTION");return"move("+b+","+c+","+a+");\n"};Blockly.Python.motor_stop=function(a){return"stop();\n"};Blockly.Python.music={};Blockly.Python.MusicMidiSetup=function(a){Blockly.Python.addInclude("SPI","#include ");Blockly.Python.addInclude("SD","#include ");Blockly.Python.addInclude("MusicPlayer","#include \n");a="player.beginInMidiFmt();\n player.midiSetInit("+a.getFieldValue("INSTRUMENT")+", "+a.getFieldValue("VOLUME")+");\n";Blockly.Python.addSetup("music_setup",a);return""}; Blockly.Python.MusicSetVolume=function(a){return"player.setVolume("+a.getFieldValue("VOLUME")+");\n"};Blockly.Python.MusicSetInstrument=function(a){return"player.midiSetInstrument("+a.getFieldValue("INSTRUMENT")+");\n"};Blockly.Python.MusicNote=function(a){return[a.getFieldValue("NOTE"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.MusicBeat=function(a){return[a.getFieldValue("BEAT"),Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.MusicPlayTone=function(a){var b=Blockly.Python.valueToCode(a,"NOTE",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"DURATION",Blockly.Python.ORDER_ATOMIC);return"player.midiPlay("+b+", "+a+");\n"};Blockly.Python.MusicRest=function(a){return"delay("+Blockly.Python.valueToCode(a,"BEAT",Blockly.Python.ORDER_ATOMIC)+");\n"}; Blockly.Python.Music_mp3_setup=function(a){Blockly.Python.addInclude("SPI","#include ");Blockly.Python.addInclude("SD","#include ");Blockly.Python.addInclude("MusicPlayer","#include \n");a=a.getFieldValue("SETVOL")||50;Blockly.Python.addDeclaration("mp3_dec","int _musicPlayerVolume = "+a+";\nint _musicVolumeMappingRead, _musicVolumeMappingSet;\n");Blockly.Python.addSetup("mp3_setup"," Serial.begin(9600);\n delay(2000);\n player.keyDisable(); //keys disable first;\n player.begin(); //will initialize the hardware and set default mode to be normal.\n player.setVolume(_musicPlayerVolume);\n"); Blockly.Python.addFunction("func_musicPlaySong","/*\n* Music Function: Music Set Play Song\n*/\nvoid _musicPlaySong(String songname) {\n int songNameLength = songname.length() + 1;\n char songNameBuf[songNameLength];\n songname.toCharArray(songNameBuf, songNameLength);\n\n delay(50);\n player.opPause();\n player.setPlayMode(PM_REPEAT_ONE);\n player.playOne(songNameBuf);\n player.play();\n delay(50);\n}");Blockly.Python.addFunction("func__musicOperation","/* \n * Music Function: Music Operation\n */\n\nvoid _musicOperation(int operation) {\n _musicVolumeMappingRead = map(_musicPlayerVolume, 110, 10, 0, 10);\n\n if (operation == 0) { // 0: Play song\n delay(100);\n player.opResume();\n } else if (operation == 1) { // 1: Pause song\n delay(100);\n player.opPause();\n } else if (operation == 2) { // 2: Previous song\n delay(100);\n for (int a = 0; a < 1; a++) {\n player.opPreviousSong();\n player.play();\n }\n } else if (operation == 3) { // 3: Next song\n delay(100);\n for (int a = 0; a < 1; a++) {\n player.opNextSong();\n player.play();\n }\n } else if (operation == 4) { // 4: Volume Up\n\n _musicPlayerVolume = _musicPlayerVolume - 10;\n if ( _musicPlayerVolume <= 10 ) {\n _musicPlayerVolume = 10;\n }\n delay(100);\n player.setVolume(_musicPlayerVolume);\n } else if (operation == 5) { // 5: Volume Down\n\n _musicPlayerVolume = _musicPlayerVolume + 10;\n if ( _musicPlayerVolume >= 110 ) {\n _musicPlayerVolume = 110;\n }\n delay(100);\n player.setVolume(_musicPlayerVolume);\n } else if (operation == 6) { // 6: Play all song\n delay(100);\n player.setPlayMode(PM_REPEAT_LIST);\n player.scanAndPlayAll();\n player.play();\n delay(100);\n player.play();\n }\n}\n"); Blockly.Python.addFunction("func_musicSetVolume","/* \n * Music Function: Music Set Volume\n */\n\nvoid _musicSetVolume(int volume) {\n _musicVolumeMappingSet = map(volume, 0, 10, 110, 10);\n player.setVolume(_musicVolumeMappingSet);\n\n _musicPlayerVolume = _musicVolumeMappingSet;\n}\n");return""};Blockly.Python.Music_mp3_playOneWithName=function(a){return'_musicPlaySong("'+a.getFieldValue("MUSIC_NAME")+'");\n'}; Blockly.Python.Music_mp3_playAllMusic=function(a){Blockly.Python.addSetup("playMode","player.setPlayMode(PM_NORMAL_PLAY);\n ");return"player.scanAndPlayAll();\nplayer.play();\n"};Blockly.Python.Music_mp3_playSetting=function(a){return"_musicOperation("+a.getFieldValue("SETTING")+");\n"};Blockly.Python.Music_mp3_getCurrentVolume=function(a){return["_musicVolumeMappingRead",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.Music_mp3_setCurrentVolume=function(a){return"_musicSetVolume("+a.getFieldValue("VOLLEVEL")+");\n"};Blockly.Python.nbiot={};Blockly.Python.NBIoT_setup=function(a){Blockly.Python.addDeclaration("NBIoT_Dec","#define nbiotSerial Serial1\nint nbiotperiodicallyExecutionState = 0;\nint nbiotperiodicallyExecutionGap = 8;\nint serialSendState = 0;\n");Blockly.Python.addSetup("NBIoT_Setup",'nbiotSerial.begin(115200);\nnbiotSerial.write("AT+CSQ\\r\\n");\n');return""}; Blockly.Python.NBIoT_http=function(a){var b=a.getFieldValue("APIKEY");Blockly.Python.addFunction("nbiotHttprequestPOST",'void nbiotHttprequestPOST() {\n int nbiotDataLength = nbiotHTTPJSONDataSet().length() + 1;\n char nbiotDataBuf[nbiotDataLength];\n nbiotHTTPJSONDataSet().toCharArray(nbiotDataBuf, nbiotDataLength);\n if ((millis() / 1000) % 10 == 1 && serialSendState == 0) {\n nbiotSerial.write("AT+HTTPCLOSE=0\\r\\n");\n serialSendState= 1;\n; } else if ((millis() / 1000) % 10 == 2) {\n serialSendState = 0;\n } if ((millis() / 1000) % 10 == 3 && serialSendState == 0) {\n nbiotSerial.write("AT+HTTPCREATE=\\"http://api.cocorobo.cn/\\"\\r\\n");\n nbiotSerial.write("AT+HTTPHEADER=0,\\"Content-Type: application/json\\\\r\\\\n\\"\\r\\n");\n serialSendState= 1;\n } else if ((millis() / 1000) % 10 == 4) {\n serialSendState = 0;\n } if ((millis() / 1000) % 10 == 5 && serialSendState == 0) {\n nbiotSerial.write(nbiotDataBuf);\n serialSendState= 1;\n } else if ((millis() / 1000) % 10 == 6) {\n serialSendState = 0;\n } if ((millis() / 1000) % 10 == 7 && serialSendState == 0) {\n nbiotSerial.write("AT+HTTPSEND=0,1,\\"/iot/data/eventAPIKey/'+b+ '\\"\\r\\n");\n serialSendState= 1;\n } else if ((millis() / 1000) % 10 == 8) {\n serialSendState = 0;\n } }\n');b='String nbiotHTTPJSONDataSet() {\n String data = "AT+HTTPCONTENT=0,\\"{";\n';for(var c=0;c 0) { //makes sure something is ready to be read\n\n static int bufpos = 0; //starts the buffer back at the first position in the incoming serial.read\n char inchar = nbiotSerial.read(); //assigns one byte (as serial.read()'s only input one byte at a time\n if (inchar != EOPmarker) { //if the incoming character is not the byte that is the incoming package ender\n serialbuf[bufpos] = inchar; //the buffer position in the array get assigned to the current read\n bufpos++; //once that has happend the buffer advances, doing this over and over again until the end of package marker is read.\n }\n else { //once the end of package marker has been read\n serialbuf[bufpos] = 0; //restart the buff\n bufpos = 0; //restart the position of the buff\n\n Serial.println(serialbuf);\n nbiot_str = serialbuf;\n\n if (nbiot_str.charAt(1) == 'I' && nbiot_str.charAt(2) == 'P') {\n nbiot_var = midString(nbiot_str, \"+IP:\", \"\\r\");\n _IPADDR = nbiot_var;\n int i = 0;\n while (i < nbiot_var.length()) {\n if (nbiot_var.charAt(i) == '.') \n nbiot_var.setCharAt(i, ',');\n i++;\n }\n Serial.println(nbiot_var);\n _stateADDR = 1;\n }\nif (nbiot_str.charAt(1) == 'C' && nbiot_str.charAt(2) == 'P' && nbiot_str.charAt(3) == 'I' && nbiot_str.charAt(4) == 'N' && nbiot_str.charAt(7) == 'R' && nbiot_str.charAt(8) == 'E' && nbiot_str.charAt(9) == 'A' && nbiot_str.charAt(10) == 'D' && nbiot_str.charAt(11) == 'Y') {\n_stateNbiotIsOn = 1;\nSerial.println(\"NBIoT initiated.\");\ndelay(100);\nnbiotSerial.write(\"AT+CMSYSCTRL=0,2,50,300,100,800\\r\\n\");\n}\n\n }\n }\n while (Serial.available() > 0) {\n char cmd = Serial.read();\n nbiotSerial.write(cmd);\n }\n}\n"); Blockly.Python.addFunction("NBIoT_midString",'String midString(String str, String start, String finish) {\n int locStart = str.indexOf(start);\n if (locStart == -1) return "";\n locStart += start.length();\n int locFinish = str.indexOf(finish, locStart);\n if (locFinish == -1) return "";\n return str.substring(locStart, locFinish);\n}\n');return"interactiveNBIoTSerial();\n"}; Blockly.Python.NBIoT_http_thingspeak=function(a){for(var b="update?api_key="+a.getFieldValue("APIKEY")+"&",c=0;cc;c++){d="value"+(c+1);var e=Blockly.Python.valueToCode(a,"ADD"+c,Blockly.Python.ORDER_ATOMIC)||0;0");Blockly.Python.addInclude("Adafruit_SSD1351","#include ");Blockly.Python.addInclude("SPI","#include ");Blockly.Python.addDeclaration("SSD1351_CS","#define CS 8");Blockly.Python.addDeclaration("SSD1351_DC","#define DC 5");Blockly.Python.addDeclaration("SSD1351_RST","#define RST 6");Blockly.Python.addDeclaration("SSD1351_decl","Adafruit_SSD1351 tft = Adafruit_SSD1351(CS, DC, RST);");Blockly.Python.addSetup("SSD1351_begin", "tft.begin();\n tft.fillScreen(0x0000);\n",!1);return""};Blockly.Python.lcd_set_width_height=function(a){var b=Blockly.Python.valueToCode(a,"WIDTH",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"HEIGHT",Blockly.Python.ORDER_ATOMIC);return[b+", "+a,Blockly.Python.ORDER_ATOMIC]};Blockly.Python.lcd_set_position=function(a){var b=Blockly.Python.valueToCode(a,"POSX",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"POSY",Blockly.Python.ORDER_ATOMIC);return[posConvert(b,a),Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.lcd_drawline=function(a){var b=sharpTo565(Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC)),c=Blockly.Python.valueToCode(a,"POSA",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"POSB",Blockly.Python.ORDER_ATOMIC);return"tft.drawLine("+c+", "+a+", "+b+");\n"}; Blockly.Python.lcd_drawrect=function(a){var b=sharpTo565(Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC)),c=Blockly.Python.valueToCode(a,"SIZE",Blockly.Python.ORDER_ATOMIC),d=a.getFieldValue("rect_type");a=Blockly.Python.valueToCode(a,"POS",Blockly.Python.ORDER_ATOMIC);return"tft."+d+"Rect("+a+", "+c+", "+b+");\n"}; Blockly.Python.lcd_drawcircle=function(a){var b=sharpTo565(Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC)),c=a.getFieldValue("circle_type"),d=Blockly.Python.valueToCode(a,"POS",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"RADIUS",Blockly.Python.ORDER_ATOMIC);return"tft."+c+"Circle("+d+", "+a+", "+b+");\n"}; Blockly.Python.lcd_drawtriangle=function(a){var b=sharpTo565(Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC)),c=a.getFieldValue("triangle_type"),d=Blockly.Python.valueToCode(a,"POSA",Blockly.Python.ORDER_ATOMIC),e=Blockly.Python.valueToCode(a,"POSB",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"POSC",Blockly.Python.ORDER_ATOMIC);return"tft."+c+"Triangle("+d+", "+e+", "+a+","+b+");\n"}; Blockly.Python.lcd_text=function(a){var b=Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_ATOMIC),c=Blockly.Python.valueToCode(a,"POS",Blockly.Python.ORDER_ATOMIC),d=sharpTo565(Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC)),e=Blockly.Python.valueToCode(a,"SIZE",Blockly.Python.ORDER_ATOMIC);a=a.getFieldValue("print_type");return"tft.setCursor("+c+");\ntft.setTextColor("+d+");\ntft.setTextSize("+e+");\ntft."+a+"("+b+");\n"};Blockly.Python.lcd_clear=function(a){return"tft.fillScreen(0x0000);\n"}; Blockly.Python.lcd_rotation=function(a){return"tft.fillScreen(0x0000);\ntft.setRotation("+a.getFieldValue("DEGREE")+");\n"};Blockly.Python.lcd_set_color=function(a){return[a.getFieldValue("COLOR"),Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.lcd_set_colorRGB=function(a){var b=Blockly.Python.valueToCode(a,"RED_VAL",Blockly.Python.ORDER_ATOMIC),c=Blockly.Python.valueToCode(a,"GREEN_VAL",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"BLUE_VAL",Blockly.Python.ORDER_ATOMIC);return["("+b+","+c+","+a+")",Blockly.Python.ORDER_ATOMIC]};function posConvert(a,b){return a+", 128 - "+b};Blockly.Python.serial={};Blockly.Python.serial_print=function(a){for(var b=a.getFieldValue("SERIAL_ID"),c=Blockly.Python.valueToCode(a,"CONTENT",Blockly.Python.ORDER_ATOMIC)||"0",d="TRUE"==a.getFieldValue("NEW_LINE"),e=Blockly.Python.Boards.selected.serialPins[b],f=0;f");return""}; Blockly.Python.servo_write=function(a){var b=a.getFieldValue("SERVO_PIN"),c=Blockly.Python.valueToCode(a,"SERVO_ANGLE",Blockly.Python.ORDER_ATOMIC)||"90",d="myServo"+b;Blockly.Python.reservePin(a,b,Blockly.Python.PinTypes.SERVO,"Servo Write");Blockly.Python.addDeclaration("servo_"+b,"Servo "+d+";");Blockly.Python.addSetup("servo_"+b,d+".attach("+b+");",!0);return d+".write("+c+");\n"}; Blockly.Python.servo_read=function(a){var b=a.getFieldValue("SERVO_PIN"),c="myServo"+b;Blockly.Python.reservePin(a,b,Blockly.Python.PinTypes.SERVO,"Servo Read");Blockly.Python.addDeclaration("servo_"+b,"Servo "+c+";");Blockly.Python.addSetup("servo_"+b,c+".attach("+b+");",!0);return[c+".read()",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.robot_setup=function(a){var b=a.getFieldValue("YR_PIN"),c=a.getFieldValue("YL_PIN"),d=a.getFieldValue("RR_PIN"),e=a.getFieldValue("RL_PIN");Blockly.Python.reservePin(a,b,Blockly.Python.PinTypes.OUTPUT,"YR_pin");Blockly.Python.reservePin(a,c,Blockly.Python.PinTypes.OUTPUT,"YL_pin");Blockly.Python.reservePin(a,d,Blockly.Python.PinTypes.OUTPUT,"RR_pin");Blockly.Python.reservePin(a,e,Blockly.Python.PinTypes.OUTPUT,"RL_pin");Blockly.Python.addInclude("servo","#include ");Blockly.Python.addInclude("oscillator", "#include ");Blockly.Python.addInclude("EEPROM","#include ");Blockly.Python.addInclude("SERVO_QUANT_AMOUNTS","#define N_SERVOS 4");Blockly.Python.addInclude("EEPROM_TRIM","#define EEPROM_TRIM false");Blockly.Python.addInclude("SERVO_TRIMRR","#define TRIM_RR 7");Blockly.Python.addInclude("SERVO_TRIMRL","#define TRIM_RL 4");Blockly.Python.addInclude("SERVO_TRIMYR","#define TRIM_YR 4");Blockly.Python.addInclude("SERVO_TRIMYL","#define TRIM_YL 7\n");Blockly.Python.addDeclaration("robot_def", "#define PIN_YR "+b+"\n#define PIN_YL "+c+"\n#define PIN_RR "+d+"\n#define PIN_RL "+e+"\n#define INTERVALTIME 10.0\n\nOscillator servo[N_SERVOS];\n\nvoid goingUp(int tempo);\nvoid drunk (int tempo);\nvoid noGravity(int tempo);\nvoid kickLeft(int tempo);\nvoid kickRight(int tempo);\nvoid run(int steps, int T = 500);\nvoid walk(int steps, int T = 1000);\nvoid backyard(int steps, int T = 3000);\nvoid backyardSlow(int steps, int T = 5000);\nvoid turnLeft(int steps, int T = 3000);\nvoid turnRight(int steps, int T = 3000);\nvoid moonWalkLeft(int steps, int T = 1000);\nvoid moonWalkRight(int steps, int T = 1000);\nvoid crusaito(int steps, int T = 1000);\nvoid swing(int steps, int T = 1000);\nvoid upDown(int steps, int T = 1000);\nvoid flapping(int steps, int T = 1000);\n"); Blockly.Python.addSetup("servo_setup","servo[0].attach(PIN_RR);\n servo[1].attach(PIN_RL);\n servo[2].attach(PIN_YR);\n servo[3].attach(PIN_YL);");Blockly.Python.addSetup("trim_setup","int trim;");Blockly.Python.addSetup("eeprom_setup",'if (EEPROM_TRIM) {\n for (int x = 0; x < 4; x++) {\n trim = EEPROM.read(x);\n if (trim > 128)trim = trim - 256;\n Serial.print("TRIM ");\n Serial.print(x);\n Serial.print(" en ");\n Serial.println(trim);\n servo[x].SetTrim(trim);\n }\n }\n else {\n servo[0].SetTrim(TRIM_RR);\n servo[1].SetTrim(TRIM_RL);\n servo[2].SetTrim(TRIM_YR);\n servo[3].SetTrim(TRIM_YL);\n }'); Blockly.Python.addFunction("dance","void dance() {\n for ( int i = 0; i < 4; i++ ) {\n servo[i].SetPosition(90);\n }\n primera_parte();\n segunda_parte();\n moonWalkLeft(4, t * 2);\n moonWalkRight(4, t * 2);\n moonWalkLeft(4, t * 2);\n moonWalkRight(4, t * 2);\n primera_parte();\n crusaito(1, t * 8);\n crusaito(1, t * 7);\n for (int i = 0; i < 16; i++) {\n flapping(1, t / 4);\n delay(3 * t / 4);\n }\n moonWalkRight(4, t * 2);\n moonWalkLeft(4, t * 2);\n moonWalkRight(4, t * 2);\n moonWalkLeft(4, t * 2);\n drunk(t * 4);\n drunk(t * 4);\n kickLeft(t);\n kickRight(t);\n delay(t * 4);\n drunk(t / 2);\n delay(t * 4);\n walk(2, t * 2);\n backyard(2, t * 2);\n goingUp(t * 2);\n goingUp(t * 1);\n noGravity(t * 2);\n crusaito(1, t * 2);\n crusaito(1, t * 8);\n crusaito(1, t * 2);\n crusaito(1, t * 8);\n crusaito(1, t * 2);\n crusaito(1, t * 3);\n delay(t);\n primera_parte();\n for (int i = 0; i < 32; i++) {\n flapping(1, t / 2);\n delay(t / 2);\n }\n for ( int i = 0; i < 4; i++ ) {\n servo[i].SetPosition(90);\n }\n}\n"); Blockly.Python.addFunction("oscillate","void oscillate(int A[N_SERVOS], int O[N_SERVOS], int T, double phase_diff[N_SERVOS]) {\n for (int i = 0; i < 4; i++) {\n servo[i].SetO(O[i]);\n servo[i].SetA(A[i]);\n servo[i].SetT(T);\n servo[i].SetPh(phase_diff[i]);\n }\n double ref = millis();\n for (double x = ref; x < T + ref; x = millis()) {\n for (int i = 0; i < 4; i++) {\n servo[i].refresh();\n }\n }\n}");Blockly.Python.addFunction("moveNServos","unsigned long final_time;\nunsigned long interval_time;\nint oneTime;\nint iteration;\nfloat increment[N_SERVOS];\nint oldPosition[] = {90, 90, 90, 90};\n\nvoid moveNServos(int time, int newPosition[]) {\n for (int i = 0; i < N_SERVOS; i++) increment[i] = ((newPosition[i]) - oldPosition[i]) / (time / INTERVALTIME);\n final_time = millis() + time;\n iteration = 1;\n while (millis() < final_time) { //Javi del futuro cambia esto\n interval_time = millis() + INTERVALTIME;\n oneTime = 0;\n while (millis() < interval_time) {\n if (oneTime < 1) {\n for (int i = 0; i < N_SERVOS; i++) {\n servo[i].SetPosition(oldPosition[i] + (iteration * increment[i]));\n }\n iteration++;\n oneTime++;\n }\n }\n }\n for (int i = 0; i < N_SERVOS; i++) {\n oldPosition[i] = newPosition[i];\n }\n}"); Blockly.Python.addFunction("goingUp","void goingUp(int tempo) {\n pause = millis();\n for (int i = 0; i < 4; i++) servo[i].SetPosition(90);\n delay(tempo);\n servo[0].SetPosition(80);\n servo[1].SetPosition(100);\n delay(tempo);\n servo[0].SetPosition(70);\n servo[1].SetPosition(110);\n delay(tempo);\n servo[0].SetPosition(60);\n servo[1].SetPosition(120);\n delay(tempo);\n servo[0].SetPosition(50);\n servo[1].SetPosition(130);\n delay(tempo);\n servo[0].SetPosition(40);\n servo[1].SetPosition(140);\n delay(tempo);\n servo[0].SetPosition(30);\n servo[1].SetPosition(150);\n delay(tempo);\n servo[0].SetPosition(20);\n servo[1].SetPosition(160);\n delay(tempo);\n while (millis() < pause + 8 * t);\n}"); Blockly.Python.addFunction("primera_parte","void primera_parte() {\n int move1[4] = {60, 120, 90, 90};\n int move2[4] = {90, 90, 90, 90};\n int move3[4] = {40, 140, 90, 90};\n for (int x = 0; x < 3; x++) {\n for (int i = 0; i < 3; i++) {\n lateral_fuerte(1, t / 2);\n lateral_fuerte(0, t / 4);\n lateral_fuerte(1, t / 4);\n delay(t);\n }\n pause = millis();\n for (int i = 0; i < 4; i++) servo[i].SetPosition(90);\n moveNServos(t * 0.4, move1);\n moveNServos(t * 0.4, move2);\n while (millis() < (pause + t * 2));\n }\n for (int i = 0; i < 2; i++) {\n lateral_fuerte(1, t / 2);\n lateral_fuerte(0, t / 4);\n lateral_fuerte(1, t / 4);\n delay(t);\n }\n pause = millis();\n for (int i = 0; i < 4; i++) servo[i].SetPosition(90);\n crusaito(1, t * 1.4);\n moveNServos(t * 1, move3);\n for (int i = 0; i < 4; i++) servo[i].SetPosition(90);\n while (millis() < (pause + t * 4));\n}"); Blockly.Python.addFunction("segunda_parte","void segunda_parte() {\n int move1[4] = {90, 90, 80, 100};\n int move2[4] = {90, 90, 100, 80};\n int move3[4] = {90, 90, 80, 100};\n int move4[4] = {90, 90, 100, 80};\n int move5[4] = {40, 140, 80, 100};\n int move6[4] = {40, 140, 100, 80};\n int move7[4] = {90, 90, 80, 100};\n int move8[4] = {90, 90, 100, 80};\n int move9[4] = {40, 140, 80, 100};\n int move10[4] = {40, 140, 100, 80};\n int move11[4] = {90, 90, 80, 100};\n int move12[4] = {90, 90, 100, 80};\n for (int x = 0; x < 7; x++) {\n for (int i = 0; i < 3; i++) {\n pause = millis();\n moveNServos(t * 0.15, move1);\n moveNServos(t * 0.15, move2);\n moveNServos(t * 0.15, move3);\n moveNServos(t * 0.15, move4);\n while (millis() < (pause + t));\n }\n pause = millis();\n moveNServos(t * 0.15, move5);\n moveNServos(t * 0.15, move6);\n moveNServos(t * 0.15, move7);\n moveNServos(t * 0.15, move8);\n while (millis() < (pause + t));\n }\n for (int i = 0; i < 3; i++) {\n pause = millis();\n moveNServos(t * 0.15, move9);\n moveNServos(t * 0.15, move10);\n moveNServos(t * 0.15, move11);\n moveNServos(t * 0.15, move12);\n while (millis() < (pause + t));\n }\n}"); Blockly.Python.addFunction("lateral_fuerte","void lateral_fuerte(boolean side, int tempo) {\n for (int i = 0; i < 4; i++) servo[i].SetPosition(90);\n if (side) servo[0].SetPosition(40);\n else servo[1].SetPosition(140);\n delay(tempo / 2);\n servo[0].SetPosition(90);\n servo[1].SetPosition(90);\n delay(tempo / 2);\n}");Blockly.Python.addFunction("drunk","void drunk (int tempo) {\n pause = millis();\n int move1[] = {60, 70, 90, 90};\n int move2[] = {110, 120, 90, 90};\n int move3[] = {60, 70, 90, 90};\n int move4[] = {110, 120, 90, 90};\n moveNServos(tempo * 0.235, move1);\n moveNServos(tempo * 0.235, move2);\n moveNServos(tempo * 0.235, move3);\n moveNServos(tempo * 0.235, move4);\n while (millis() < (pause + tempo));\n}"); Blockly.Python.addFunction("noGravity","void noGravity(int tempo) {\n int move1[4] = {120, 140, 90, 90};\n int move2[4] = {140, 140, 90, 90};\n int move3[4] = {120, 140, 90, 90};\n int move4[4] = {90, 90, 90, 90};\n for (int i = 0; i < 4; i++) servo[i].SetPosition(90);\n for (int i = 0; i < N_SERVOS; i++) oldPosition[i] = 90;\n moveNServos(tempo * 2, move1);\n moveNServos(tempo * 2, move2);\n delay(tempo * 2);\n moveNServos(tempo * 2, move3);\n moveNServos(tempo * 2, move4);\n}");Blockly.Python.addFunction("kickLeft", "void kickLeft(int tempo) {\n for (int i = 0; i < 4; i++) servo[i].SetPosition(90);\n delay(tempo);\n servo[0].SetPosition(50);\n servo[1].SetPosition(70);\n delay(tempo);\n servo[0].SetPosition(80);\n servo[1].SetPosition(70);\n delay(tempo / 4);\n servo[0].SetPosition(30);\n servo[1].SetPosition(70);\n delay(tempo / 4);\n servo[0].SetPosition(80);\n servo[1].SetPosition(70);\n delay(tempo / 4);\n servo[0].SetPosition(30);\n servo[1].SetPosition(70);\n delay(tempo / 4);\n servo[0].SetPosition(80);\n servo[1].SetPosition(70);\n delay(tempo);\n}"); Blockly.Python.addFunction("kickRight","void kickRight(int tempo) {\n for (int i = 0; i < 4; i++) servo[i].SetPosition(90);\n delay(tempo);\n servo[0].SetPosition(110);\n servo[1].SetPosition(130);\n delay(tempo);\n servo[0].SetPosition(110);\n servo[1].SetPosition(100);\n delay(tempo / 4);\n servo[0].SetPosition(110);\n servo[1].SetPosition(150);\n delay(tempo / 4);\n servo[0].SetPosition(110);\n servo[1].SetPosition(80);\n delay(tempo / 4);\n servo[0].SetPosition(110);\n servo[1].SetPosition(150);\n delay(tempo / 4);\n servo[0].SetPosition(110);\n servo[1].SetPosition(100);\n delay(tempo);\n}"); Blockly.Python.addFunction("walk","void walk(int steps, int T) {\n int A[4] = {15, 15, 30, 30};\n int O[4] = {0, 0, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}");Blockly.Python.addFunction("run","void run(int steps, int T) {\n int A[4] = {10, 10, 10, 10};\n int O[4] = {0, 0, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}"); Blockly.Python.addFunction("backyard","void backyard(int steps, int T) {\n int A[4] = {15, 15, 30, 30};\n int O[4] = {0, 0, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(-90), DEG2RAD(-90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}");Blockly.Python.addFunction("backyardSlow","void backyardSlow(int steps, int T) {\n int A[4] = {15, 15, 30, 30};\n int O[4] = {0, 0, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(-90), DEG2RAD(-90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}"); Blockly.Python.addFunction("turnLeft","void turnLeft(int steps, int T) {\n int A[4] = {20, 20, 10, 30};\n int O[4] = {0, 0, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}");Blockly.Python.addFunction("turnRight","void turnRight(int steps, int T) {\n int A[4] = {20, 20, 30, 10};\n int O[4] = {0, 0, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}"); Blockly.Python.addFunction("turnRight","void turnRight(int steps, int T) {\n int A[4] = {20, 20, 30, 10};\n int O[4] = {0, 0, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}");Blockly.Python.addFunction("turnRight","void turnRight(int steps, int T) {\n int A[4] = {20, 20, 30, 10};\n int O[4] = {0, 0, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}"); Blockly.Python.addFunction("crusaito","void crusaito(int steps, int T) {\n int A[4] = {25, 25, 30, 30};\n int O[4] = { - 15, 15, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180 + 120), DEG2RAD(90), DEG2RAD(90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}");Blockly.Python.addFunction("swing","void swing(int steps, int T) {\n int A[4] = {25, 25, 0, 0};\n int O[4] = { -15, 15, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}"); Blockly.Python.addFunction("upDown","void upDown(int steps, int T) {\n int A[4] = {25, 25, 0, 0};\n int O[4] = { -15, 15, 0, 0};\n double phase_diff[4] = {DEG2RAD(180), DEG2RAD(0), DEG2RAD(270), DEG2RAD(270)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}");Blockly.Python.addFunction("flapping","void flapping(int steps, int T) {\n int A[4] = {15, 15, 8, 8};\n int O[4] = { -A[0], A[1], 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180), DEG2RAD(90), DEG2RAD(-90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}")}; Blockly.Python.robot_set_movement=function(a){var b=Blockly.Python.valueToCode(a,"MOVEMENT",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"TEMPO",Blockly.Python.ORDER_ATOMIC);Blockly.Python.addDeclaration("robot_setmovement_def","int t = "+a+";\ndouble pause = 0;\n");switch(b){case "goingUp":case "drunk":case "kickLeft":case "kickRight":a="(";break;default:a="(1, "}return b+a+" 2*t);\n"};Blockly.Python.robot_movement=function(a){return[a.getFieldValue("MOVEMENT"),Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.robot_tempo=function(a){return[a.getFieldValue("TEMPO"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.spi={};Blockly.Python.spi_setup=function(a){var b=a.getFieldValue("SPI_ID"),c=a.getFieldValue("SPI_SHIFT_ORDER"),d=a.getFieldValue("SPI_CLOCK_DIVIDE");a=a.getFieldValue("SPI_MODE");Blockly.Python.addInclude("spi","#include ");Blockly.Python.addSetup("spi_order",b+".setBitOrder("+c+");",!0);Blockly.Python.addSetup("spi_mode",b+".setDataMode("+a+");",!0);Blockly.Python.addSetup("spi_div",b+".setClockDivider("+d+");",!0);Blockly.Python.addSetup("spi_begin",b+".begin();",!0);return""}; Blockly.Python.spi_transfer=function(a){var b=a.getFieldValue("SPI_ID"),c=a.getFieldValue("SPI_SS"),d=Blockly.Python.valueToCode(a,"SPI_DATA",Blockly.Python.ORDER_ATOMIC)||"0";Blockly.Python.addInclude("spi","#include ");Blockly.Python.addSetup("spi_begin",b+".begin();",!1);for(var e=Blockly.Python.Boards.selected.spiPins[b],f=0;f");Blockly.Python.addDeclaration(e,"Stepper "+e+"("+f+", "+b+", "+c+");");Blockly.Python.addSetup(e,e+".setSpeed("+g+");",!0);return""};Blockly.Python.stepper_step=function(a){var b="stepper_"+a.getFieldValue("STEPPER_NAME");a=Blockly.Python.valueToCode(a,"STEPPER_STEPS",Blockly.Python.ORDER_ATOMIC)||"0";return b+".step("+a+");\n"};Blockly.Python.text={};Blockly.Python.text=function(a){return[Blockly.Python.quote_(a.getFieldValue("TEXT")),Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.text_join=function(a){if(0==a.itemCount_)return['""',Blockly.Python.ORDER_ATOMIC];if(1==a.itemCount_)return["String("+(Blockly.Python.valueToCode(a,"ADD0",Blockly.Python.ORDER_UNARY_POSTFIX)||'""')+")",Blockly.Python.ORDER_UNARY_POSTFIX];var b=[];for(var c=0;c");var b="sonar"+a.getFieldValue("NUMBER"),c=a.getFieldValue("TRIG_PIN"),d=a.getFieldValue("ECHO_PIN");Blockly.Python.reservePin(a,c,Blockly.Python.PinTypes.OUTPUT,"Sonar_Trig_Pin"+c);Blockly.Python.reservePin(a,d,Blockly.Python.PinTypes.OUTPUT,"Sonar_Echo_Pin"+d);a=a.getFieldValue("MAXDIST");var e="TRIG_"+c,f="ECHO_"+d,g="MAXDIST_"+c+"_"+d;Blockly.Python.addDeclaration("define_"+b,"#define "+e+" "+ c+"\n#define "+f+" "+d+"\n#define "+g+" "+a+"\nNewPing "+b+"("+e+", "+f+", "+g+");\n");return""};Blockly.Python.sonar_read_dist=function(a){return["sonar"+a.getFieldValue("NUMBER")+".ping_cm()",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.infraredRay_setup=function(a){Blockly.Python.addInclude("IRLib","#include \n#include \n#include \nIRdecode myDecoder;\n#include \nIRrecv myReceiver(A2);\n");Blockly.Python.addDeclaration("IR_keys_def","#define KEYPAD_UP 0xFF18E7\n#define KEYPAD_DOWN 0xFF4AB5\n#define KEYPAD_LEFT 0xFF10EF\n#define KEYPAD_RIGHT 0xFF5AA5\n#define KEYPAD_OK 0xFF38C7\n#define KEYPAD_1 0xFFA25D\n#define KEYPAD_2 0xFF629D\n#define KEYPAD_3 0xFFE21D\n#define KEYPAD_4 0xFF22DD\n#define KEYPAD_5 0xFF02FD\n#define KEYPAD_6 0xFFC23D\n#define KEYPAD_7 0xFFE01F\n#define KEYPAD_8 0xFFA857\n#define KEYPAD_9 0xFF906F\n#define KEYPAD_0 0xFF9867\n#define KEYPAD_STAR 0xFF6897\n#define KEYPAD_NUMSIGN 0xFFB04F\n"); Blockly.Python.addSetup("IR_setup","Serial.begin(9600);\ndelay(2000);\nmyReceiver.enableIRIn();",!1);return"if (myReceiver.getResults()) {\nmyDecoder.decode(); \n// myDecoder.dumpResults(true);\nmyReceiver.enableIRIn();\n}\n"};Blockly.Python.infraredRay_receive_val=function(a){return["myDecoder.value",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.infraredRay_send_val=function(a){return[a.getFieldValue("VALTYPE"),Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.RTC_setup=function(a){Blockly.Python.addInclude("RTC_include",'#include //include Wire.h library \n#include "RTClib.h" //include Adafruit RTC library');Blockly.Python.addDeclaration("RTC_declaration",'RTC_DS3231 rtc; //Make a RTC DS3231 object\n //Set the names of days\nchar daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};');Blockly.Python.addSetup("RTC_setup",' Serial.begin(9600);\n if (! rtc.begin()) {\n Serial.println("Couldn\'t find RTC");\n while (1);\n }\n //Setup of time if RTC lost power or time is not set\n if (rtc.lostPower()) {\n //Sets the code compilation time to RTC DS3231\n rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));\n }\n'); return"DateTime now = rtc.now();\n"};Blockly.Python.RTC_setDateTime=function(a){var b=a.getFieldValue("hour"),c=a.getFieldValue("minute"),d=a.getFieldValue("second"),e=a.getFieldValue("year"),f=a.getFieldValue("month");a=a.getFieldValue("day");Blockly.Python.addSetup("RTC_set","rtc.adjust(DateTime("+e+","+f+","+a+","+b+","+c+","+d+"));");return""}; Blockly.Python.RTC_getDate=function(a){var b="";switch(a.getFieldValue("date_detail")){case "year":b="now.year()";break;case "month":b="now.month()";break;case "day":b="now.day()"}return[b,Blockly.Python.ORDER_ATOMIC]};Blockly.Python.RTC_getTime=function(a){var b="";switch(a.getFieldValue("time_detail")){case "hour":b="now.hour()";break;case "minute":b="now.minute()";break;case "second":b="now.second()"}return[b,Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.RTC_getWeek=function(a){return["daysOfTheWeek[now.dayOfTheWeek()]",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.PulseSensor_setup=function(a){a=a.getFieldValue("PIN");Blockly.Python.addInclude("PulseSensor_inc","#define USE_ARDUINO_INTERRUPTS true\n#include ");Blockly.Python.addDeclaration("PulseSensor_dec","const int OUTPUT_TYPE = SERIAL_PLOTTER;\nconst int PIN_INPUT = "+a+";\nconst int THRESHOLD = 550;\nPulseSensorPlayground pulseSensor;");Blockly.Python.addSetup("PulseSensor_setup","pulseSensor.analogInput(PIN_INPUT);\n pulseSensor.setSerial(Serial);\n pulseSensor.setOutputType(OUTPUT_TYPE);\n pulseSensor.setThreshold(THRESHOLD);\n if (!pulseSensor.begin())\n {\n for (;;) {}\n }"); return""};Blockly.Python.PulseSensor_getBPM=function(a){return["pulseSensor.getBeatsPerMinute()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.PulseSensor_Heart_Beats=function(a){return["pulseSensor.sawStartOfBeat()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.PulseSensor_Heart_noBeats=function(a){return["pulseSensor.isInsideBeat() == false",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.PulseSensor_print=function(a){return"pulseSensor.outputSample();\n"}; Blockly.Python.Encoder_Setup=function(a){a=a.getFieldValue("PIN");Blockly.Python.addDeclaration("Encoder_dec","int encoderCounter = 0;\nunsigned long encoderTime = 0, old_encoderTime = 0;\nunsigned long encoderTime1 = 0;\nfloat encoderSpeed;\n");Blockly.Python.addSetup("Encoder_setup","Serial.begin(9600);\nattachInterrupt("+a+", encoderCount_CallBack, FALLING);\n");Blockly.Python.addFunction("Encoder_func","bool SpeedDetection()\n{\n encoderTime = millis();\n if (abs(encoderTime - old_encoderTime) >= 1000)\n {\n detachInterrupt("+ a+");\n encoderSpeed = (float)encoderCounter * 60 / 20;\n encoderCounter = 0;\n old_encoderTime = millis();\n attachInterrupt("+a+", encoderCount_CallBack, FALLING); \n return 1;\n }\n else\n return 0;\n}\n\nvoid encoderCount_CallBack()\n{\n encoderCounter++;\n}");return"SpeedDetection();\n"};Blockly.Python.Encoder_getRotationSpeed=function(a){return["encoderSpeed",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.RFID_Setup=function(a){Blockly.Python.addInclude("RFID_include","#include \n#include ");Blockly.Python.addDeclaration("RFID_dec",'#define SS_PIN SS\nMFRC522 rfid(SS_PIN); // Instance of the class\nMFRC522::MIFARE_Key key;\nbyte nuidPICC[4];\nchar NUID[4];\nString nuid_str="null";');Blockly.Python.addSetup("RFID_setup",'Serial.begin(9600);\nSPI.begin(); // Init SPI bus\nrfid.PCD_Init(); // Init MFRC522\nfor (byte i = 0; i < 6; i++) {\n key.keyByte[i] = 0xFF;\n}\nSerial.println(F("This code scan the MIFARE Classsic NUID."));\nSerial.print(F("Using the following key:"));\nprintHex(key.keyByte, MFRC522::MF_KEY_SIZE);\n'); Blockly.Python.addFunction("RFID_printHex","void printHex(byte *buffer, byte bufferSize) {\n for (byte i = 0; i < bufferSize; i++) {\n Serial.print(buffer[i], HEX);\n }\n}");Blockly.Python.addFunction("RFID_tohex","String tohex(int n) {\n if (n == 0) {\n return \"00\"; //n\u4e3a0\n }\n String result = \"\";\n char _16[] = {'0','1','2','3','4','5','6','7', '8','9','A','B','C','D','E','F'};\n const int radix = 16;\n while (n) {\n int i = n % radix;\n result = _16[i] + result;\n n /= radix;\n }\n if (result.length() < 2) {\n result = '0' + result;\n }\n return result;\n}"); return'// Look for new cards\nif (!rfid.PICC_IsNewCardPresent())\n return;\nif (!rfid.PICC_ReadCardSerial())\n return;\nMFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);\n// Check is the PICC of Classic MIFARE type\nif (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&\n piccType != MFRC522::PICC_TYPE_MIFARE_1K &&\n piccType != MFRC522::PICC_TYPE_MIFARE_4K) {\n Serial.println(F("Your tag is not supported"));\n return;\n}\n// Store NUID into nuidPICC array\nfor (byte i = 0; i < 4; i++) {\n nuidPICC[i] = rfid.uid.uidByte[i];\n}\n//Store NUID into nuid_str\nnuid_str="";\nfor (byte i = 0; i < 4; i++) {\n nuid_str += tohex(rfid.uid.uidByte[i]);\n}\n// Halt PICC\nrfid.PICC_HaltA();\n// Stop encryption on PCD\nrfid.PCD_StopCrypto1();\n'}; Blockly.Python.RFID_ReadID=function(a){return["nuid_str",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.GPS_setup=function(a){Blockly.Python.addInclude("GPS_include","#include \nSoftwareSerial gpsSerial(11,10);// MOSI");Blockly.Python.addDeclaration("GPS_Dec","struct\n{\n char GPS_Buffer[80];\n bool isGetData;\n bool isParseData;\n char UTCTime[11];\n char latitude[11];\n char N_S[2];\n char longitude[12];\n char E_W[2];\n bool isUsefull;\n} Save_Data;\nconst unsigned int gpsRxBufferLength = 600;\nchar gpsRxBuffer[gpsRxBufferLength];\nunsigned int ii = 0;\nString GPSMODULEstringLat, GPSMODULEstringLong, GPSMODULEgpsLatitude, GPSMODULEgpsLongitude;\nfloat GPSMODULEfloatLat, GPSMODULEfloatLon;\n");Blockly.Python.addSetup("GPS_Setup", "gpsSerial.begin(9600);\n Save_Data.isGetData = false;\n Save_Data.isParseData = false;\n Save_Data.isUsefull = false;\n");Blockly.Python.addFunction("gpsMoudle","void gpsModule() {\n gpsRead();\n parseGpsBuffer();\n convertRealCoordinate();\n}\n");Blockly.Python.addFunction("convertRealCoordinate","void convertRealCoordinate() {\n String GPSMODULEstringLat = Save_Data.latitude;\n String GPSMODULEstringLon = Save_Data.longitude;\n float GPSMODULEfloatLat = GPSMODULEstringLat.toFloat();\n float GPSMODULEfloatLon = GPSMODULEstringLon.toFloat();\n GPSMODULEgpsLatitude = String(convertDegMinToDecDeg(GPSMODULEfloatLat), 7);\n GPSMODULEgpsLongitude = String(convertDegMinToDecDeg(GPSMODULEfloatLon), 7);\n}\n"); Blockly.Python.addFunction("convertDegMinToDecDeg","double convertDegMinToDecDeg (float degMin) {\n double min = 0.0;\n double decDeg = 0.0;\n //get the minutes, fmod() requires double\n min = fmod((double)degMin, 100.0);\n //rebuild coordinates in decimal degrees\n degMin = (int) ( degMin / 100 );\n decDeg = degMin + ( min / 60 );\n return decDeg;\n}\n");Blockly.Python.addFunction("errorLog",'void errorLog(int num)\n{\n Serial.print("ERROR");\n Serial.println(num);\n while (1)\n {\n Serial.flush();\n }\n}\n'); Blockly.Python.addFunction("printGpsBuffer",'void printGpsBuffer()\n{\n if (Save_Data.isParseData)\n {\n Save_Data.isParseData = false;\n Serial.print("Save_Data.UTCTime = ");\n Serial.println(Save_Data.UTCTime);\n if (Save_Data.isUsefull)\n {\n Save_Data.isUsefull = false;\n Serial.print("Save_Data.latitude = ");\n Serial.println(Save_Data.latitude);\n Serial.print("Save_Data.N_S = ");\n Serial.println(Save_Data.N_S);\n Serial.print("Save_Data.longitude = ");\n Serial.println(Save_Data.longitude);\n Serial.print("Save_Data.E_W = ");\n Serial.println(Save_Data.E_W);\n } else {\n Serial.println("GPS DATA is not usefull!");\n }\n }\n}\n'); Blockly.Python.addFunction("parseGpsBuffer",'void parseGpsBuffer()\n{\n char *subString;\n char *subStringNext;\n if (Save_Data.isGetData)\n {\n Save_Data.isGetData = false;\n Serial.println("**************");\n Serial.println(Save_Data.GPS_Buffer);\n for (int i = 0 ; i <= 6 ; i++)\n {\n if (i == 0)\n {\n if ((subString = strstr(Save_Data.GPS_Buffer, ",")) == NULL)\n errorLog(1); // Parse error\n }\n else\n {\n subString++;\n if ((subStringNext = strstr(subString, ",")) != NULL)\n {\n char usefullBuffer[2];\n switch (i)\n {\n case 1: memcpy(Save_Data.UTCTime, subString, subStringNext - subString); break;\n case 2: memcpy(usefullBuffer, subString, subStringNext - subString); break;\n case 3: memcpy(Save_Data.latitude, subString, subStringNext - subString); break;\n case 4: memcpy(Save_Data.N_S, subString, subStringNext - subString); break;\n case 5: memcpy(Save_Data.longitude, subString, subStringNext - subString); break;\n case 6: memcpy(Save_Data.E_W, subString, subStringNext - subString); break;\n default: break;\n }\n subString = subStringNext;\n Save_Data.isParseData = true;\n if (usefullBuffer[0] == \'A\')\n Save_Data.isUsefull = true;\n else if (usefullBuffer[0] == \'V\')\n Save_Data.isUsefull = false;\n }\n else\n {\n errorLog(2);\n }\n }\n }\n }\n}\n'); Blockly.Python.addFunction("gpsRead",'void gpsRead() {\n while (gpsSerial.available())\n {\n gpsRxBuffer[ii++] = gpsSerial.read();\n if (ii == gpsRxBufferLength)clrGpsRxBuffer();\n }\n char* GPS_BufferHead;\n char* GPS_BufferTail;\n if ((GPS_BufferHead = strstr(gpsRxBuffer, "$GPRMC,")) != NULL || (GPS_BufferHead = strstr(gpsRxBuffer, "$GNRMC,")) != NULL )\n {\n if (((GPS_BufferTail = strstr(GPS_BufferHead, "\\r\\n")) != NULL) && (GPS_BufferTail > GPS_BufferHead))\n {\n memcpy(Save_Data.GPS_Buffer, GPS_BufferHead, GPS_BufferTail - GPS_BufferHead);\n Save_Data.isGetData = true;\n clrGpsRxBuffer();\n }\n }\n}\n'); Blockly.Python.addFunction("clrGpsRxBuffer","void clrGpsRxBuffer(void) {\n memset(gpsRxBuffer, 0, gpsRxBufferLength);\n ii = 0;\n}\n");return["gpsModule();\n",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.GPS_getLatitude=function(a){return["GPSMODULEgpsLatitude",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.GPS_getLongitude=function(a){return["GPSMODULEgpsLongitude",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.water_temp_sensor_setup=function(a){a.getFieldValue("water_temp_sensor_setup_dropdown");a=a.getFieldValue("water_temp_sensor_setup_pin");Blockly.Python.addDeclaration("water_temp_sensor_setup_DECLARATION","#include \nint DS18S20_Pin = "+a+";\nOneWire ds(DS18S20_Pin);\n");Blockly.Python.addFunction("water_temp_sensor_setup_FUNCTION",'float getDS18S20WaterTemp() {\nbyte data[12];\nbyte addr[8];\nif ( !ds.search(addr)) {\n ds.reset_search();\n return -1000;\n}\nif ( OneWire::crc8( addr, 7) != addr[7]) {\n Serial.println("CRC is not valid!");\n return -1000;\n}\nif ( addr[0] != 0x10 && addr[0] != 0x28) {\n Serial.print("Device is not recognized");\n return -1000;\n}\nds.reset(); \nds.select(addr); \nds.write(0x44, 1); \nbyte present = ds.reset(); \nds.select(addr); \nds.write(0xBE); \nfor (int i = 0; i < 9; i++) { \n data[i] = ds.read(); \n} \nds.reset_search();\nbyte MSB = data[1];\nbyte LSB = data[0];\nfloat tempRead = ((MSB << 8) | LSB);\nfloat TemperatureSum = tempRead / 16;\nreturn TemperatureSum;\n}\n'); return["float getWaterTempValue = getDS18S20WaterTemp();\n",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.water_temp_sensor_get_value=function(a){return["getWaterTempValue",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.thirdparty_co2_sensor_setup=function(a){a.getFieldValue("thirdparty_co2_sensor_setup_sdapin");a.getFieldValue("thirdparty_co2_sensor_setup_sclpin");Blockly.Python.addInclude("thirdparty_co2_sensor_setup_include",'#include "Adafruit_CCS811.h"\n');Blockly.Python.addDeclaration("thirdparty_co2_sensor_setup_declaration","Adafruit_CCS811 ccs;\nuint16_t _ccs811getCO2, _ccs811getTVOC;\n");Blockly.Python.addFunction("thirdparty_co2_sensor_setup_function",'void _ccs811Setup() {\n Serial.begin(9600);\n Serial.println("CCS811 test");\n if (!ccs.begin()) {\n Serial.println("Failed to start sensor! Please check your wiring.");\n while (1);\n }\n while (!ccs.available());\n}\n\nvoid _ccs811Main() {\n if (ccs.available()) {\n if (!ccs.readData()) {\n _ccs811getCO2 = ccs.geteCO2();\n _ccs811getTVOC = ccs.getTVOC();\n }\n else {\n Serial.println("ERROR!");\n while (1);\n }\n }\n delay(100);\n}\n'); Blockly.Python.addSetup("thirdparty_co2_sensor_setup_setup","_ccs811Setup();\n");return["_ccs811Main();\n",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.thirdparty_co2_sensor_get_co2=function(a){return["_ccs811getCO2",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.thirdparty_co2_sensor_get_tvoc=function(a){return["_ccs811getTVOC",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.thirdparty_nrf24l01_setup=function(a){a.getFieldValue("thirdparty_nrf24l01_setup_dropdown_cepin");a.getFieldValue("thirdparty_nrf24l01_setup_dropdown_csnpin");a=a.getFieldValue("thirdparty_nrf24l01_setup_addr");Blockly.Python.addInclude("thirdparty_nrf24l01_setup_include","#include \n#include \n#include )\n");Blockly.Python.addDeclaration("thirdparty_nrf24l01_setup_declaration",'RF24 radio(7, 5);\nconst byte address[6] = "'+a+'";\n');Blockly.Python.addSetup("thirdparty_nrf24l01_setup_setup", "radio.begin();\n");return""};Blockly.Python.thirdparty_nrf24l01_send_data=function(a){a=a.getFieldValue("thirdparty_nrf24l01_send_data_data");Blockly.Python.addSetup("thirdparty_nrf24l01_send_data_setup","radio.openWritingPipe(address);\nradio.setPALevel(RF24_PA_MIN);\nradio.stopListening();\n");return'const char text[] = "'+a+'";\nradio.write(&text, sizeof(text));\n'}; Blockly.Python.thirdparty_nrf24l01_receive_data=function(a){Blockly.Python.addDeclaration("thirdparty_nrf24l01_receive_data_declare",'char _nrfText[32] = "";\n');Blockly.Python.addSetup("thirdparty_nrf24l01_receive_data_setup","radio.openReadingPipe(0, address);\nradio.setPALevel(RF24_PA_MIN);\nradio.startListening();\n");Blockly.Python.addFunction("thirdparty_nrf24l01_receive_data_function","void _nrfReceiveDataSet() {\n if (radio.available()) {\n radio.read(&_nrfText, sizeof(_nrfText));\n }\n}\n"); return"_nrfReceiveDataSet();\n"};Blockly.Python.thirdparty_nrf24l01_data_received=function(a){return["_nrfText",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.time={};Blockly.Python.time_delay=function(a){return"delay("+(Blockly.Python.valueToCode(a,"DELAY_TIME_MILI",Blockly.Python.ORDER_ATOMIC)||"0")+");\n"};Blockly.Python.time_delaymicros=function(a){return"delayMicroseconds("+(Blockly.Python.valueToCode(a,"DELAY_TIME_MICRO",Blockly.Python.ORDER_ATOMIC)||"0")+");\n"};Blockly.Python.time_millis=function(a){return["millis()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.time_micros=function(a){return["micros()",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.infinite_loop=function(a){return"while(true);\n"};Blockly.Python.time_chrono_setup=function(a){Blockly.Python.addInclude("chrono.h","#include \n");Blockly.Python.addDeclaration("chrono_dec","Chrono myChrono;\n")};Blockly.Python.time_chrono_reset=function(a){return"myChrono.restart();\n"};Blockly.Python.time_chrono_elapsed=function(a){return["myChrono.elapsed()",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.time_chrono_timeCheck=function(a){return["myChrono.hasPassed("+Blockly.Python.valueToCode(this,"TIME",Blockly.Python.ORDER_ATOMIC)+")",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.time_everySecond=function(a){var b=Blockly.Python.valueToCode(this,"TIME",Blockly.Python.ORDER_ATOMIC);Blockly.Python.addDeclaration("everySecondState_"+b,"int everySecondState_"+b+" = 0;");a=Blockly.Python.statementToCode(a,"STACK",Blockly.Python.ORDER_ATOMIC);return 2<=b?"if ((millis() / 1000) % "+b+" == "+(b-2)+" && everySecondState_"+b+" == 0) {\n "+a+"\n everySecondState_"+b+" = 1;\n} else if ((millis() / 1000) % "+b+" == "+(b-1)+") {\n everySecondState_"+b+" = 0;\n}\n":"if ((millis() / 100) % 10 == 1 && everySecondState_"+ b+" == 0) {\n "+a+"\n everySecondState_"+b+" = 1;\n} else if ((millis() / 100) % 10 == 2 && everySecondState_"+b+" == 1) {\n everySecondState_"+b+" = 0;\n}\n"}; Blockly.Python.time_everyMilliSecond=function(a){var b=Blockly.Python.valueToCode(this,"TIME",Blockly.Python.ORDER_ATOMIC);Blockly.Python.addDeclaration("timePeriodExecutionState_"+b,"int timePeriodExecutionState_"+b+" = 0;");a=Blockly.Python.statementToCode(a,"STACK",Blockly.Python.ORDER_ATOMIC);return"if ((millis()) % "+b+" == "+(b-1)+" && timePeriodExecutionState_"+b+" == 0) {\n "+a+"\n timePeriodExecutionState_"+b+" = 1;\n} else if ((millis()) % "+b+" == 0) {\n timePeriodExecutionState_"+b+ " = 0;\n}\n"};Blockly.Python.touch={}; Blockly.Python.touch_setup=function(a){Blockly.Python.addDeclaration("wire.h","#include \n");Blockly.Python.addDeclaration("touch_sensor_decl",'#include "Adafruit_MPR121.h"\nAdafruit_MPR121 cap = Adafruit_MPR121();\nuint16_t lasttouched = 0;\nuint16_t currtouched = 0;\n');Blockly.Python.addSetup("music_keyboard_setup",'Serial.begin(9600);\nSerial.println("Adafruit MPR121 Capacitive Touch sensor test");\n if (!cap.begin(0x5A)) {\n Serial.println("MPR121 not found, check wiring?");\n while (1);\n }\n Serial.println("MPR121 found!");\n');return""}; Blockly.Python.touch_keyboardset=function(a){for(var b=" switch (i_) {\n",c,d,e=0;e<=a.caseCount_;e++)c=a.getFieldValue("keyboard"+e)||e,d=Blockly.Python.statementToCode(a,"DO"+e),b+=" case "+c+":\n "+d+" break;\n";return"currtouched = cap.touched();\nfor (uint8_t i_=0; i_<12; i_++) {\n if ((currtouched & _BV(i_)) && !(lasttouched & _BV(i_)) ) {\n"+b+" }\nlasttouched = currtouched;\n }\n}\n"}; Blockly.Python.touch_keyboardset_loose=function(a){for(var b=" switch (i_) {\n",c,d,e=0;e<=a.caseCount_;e++)c=a.getFieldValue("keyboard"+e)||e,d=Blockly.Python.statementToCode(a,"DO"+e),b+=" case "+c+":\n "+d+" break;\n";return"for (uint8_t i_=0; i_<12; i_++) {\n if (!(currtouched & _BV(i_)) && (lasttouched & _BV(i_)) ) {\n"+b+" }\nlasttouched = 0;\n }\n}\n"}; Blockly.Python.touch_setup_1=function(a){Blockly.Python.addDeclaration("wire.h","#include \n");Blockly.Python.addDeclaration("touch_sensor_decl",'#include "Adafruit_MPR121.h"\nAdafruit_MPR121 cap = Adafruit_MPR121();\nuint16_t lasttouched = 0;\nuint16_t currtouched = 0;\n');Blockly.Python.addSetup("music_keyboard_setup",'Serial.println("Adafruit MPR121 Capacitive Touch sensor test");\n if (!cap.begin(0x5A)) {\n Serial.println("MPR121 not found, check wiring?");\n while (1);\n }\n Serial.println("MPR121 found!");\n'); return"currtouched = cap.touched();\n"};Blockly.Python.touch_each=function(a){var b=a.getFieldValue("keyboard"),c=Blockly.Python.statementToCode(a,"DO0");a=Blockly.Python.statementToCode(a,"DO1");return"if ((currtouched & _BV("+b+"))&& !(lasttouched & _BV("+b+"))){\n"+c+" lasttouched = currtouched;\n}\nif ((lasttouched & _BV("+b+")) && !(currtouched & _BV("+b+")) ) {\n"+a+" lasttouched = 0;\n}\n"};Blockly.Python.variables={};Blockly.Python.variables_get=function(a){return[Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.variables_set=function(a){var b=Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_ASSIGNMENT)||"0";if(a.childBlocks_.length){if("lists_create_with"==a.childBlocks_[0].type)return a=a.getFieldValue("VAR"),Blockly.Python.addDeclaration("create_int_list","int "+a+"[] = "+b+";\n"),"";if("lists_create_with2"==a.childBlocks_[0].type)return a=a.getFieldValue("VAR"),Blockly.Python.addDeclaration("create_string_list","String "+a+"[] = "+b+";\n"),"";a=Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"), Blockly.Variables.NAME_TYPE);return a+" = "+b+";\n"}a=Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE);return a+" = "+b+";\n"};Blockly.Python.variables_set_type=function(a){var b=Blockly.Python.valueToCode(a,"VARIABLE_SETTYPE_INPUT",Blockly.Python.ORDER_ASSIGNMENT)||"0";return["("+Blockly.Python.getArduinoType_(Blockly.Types[a.getFieldValue("VARIABLE_SETTYPE_TYPE")])+")("+b+")",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.webpage={}; Blockly.Python.webpage_label=function(a){var b='server.send(200, "text/html","

CocoRobo IoT Project

Web Dashboard

';for(var c= 0;c"+d+": \"+String("+e+')+"
'}return b+'
");\n'}; Blockly.Python.webpage_button=function(a){var b='server.send(200, "text/html","

CocoRobo IoT Project

Web Dashboard

';for(var c= 0;c"+e+"
"}return b+"