forked from blechdom/node-red-flows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ROBOTARM_withMIDI_v4.json
1 lines (1 loc) · 21.9 KB
/
ROBOTARM_withMIDI_v4.json
1
[{"id":"a07e7e4d.e2dd","type":"function","z":"dc52b959.21afb8","name":"Just get preset","func":"var servos = msg.payload.payload;\nvar last_servos = global.get(\"last_sent_servos\");\nvar robot_speed = global.get(\"robot_speed\");\nvar sameness_flag = 0;\nvar m = [];\nvar servo_command = \"\";\n\nfor(var i=0; i<servos.length; i++) {\n if(servos[i]!=last_servos[i]){\n sameness_flag=1;\n }\n}\n\nif(sameness_flag==1){\n \n m[0] = { payload: \"reset\"};\n \n for (var i=1;i<7;i++)\n {\n m[i] = { payload: servos[i-1] };\n \n var id = i;\n servo_command = servo_command + id + \":\" + servos[i-1] + \":\" + robot_speed;\n if (id == 6) {\n servo_command = servo_command + \"!\";\n }\n else {\n servo_command = servo_command + \"&\";\n }\n }\n \n m[7] = { payload: servo_command };\n global.set(\"last_sent_servos\", [...servos]);\n global.set(\"servos_preset\", servos);\n\n return m;\n\n}\n","outputs":8,"noerr":0,"x":1423,"y":499.5,"wires":[[],["f0e5f5df.8efa68"],["b879ed05.75191"],["eb3eeb15.41b978"],["377b3204.a2c96e"],["d43be5e9.3727e8"],["9fe16ce9.389b7"],["e32e2cc3.ba72","e61aee03.11fb4"]]},{"id":"fe156fc2.607ec","type":"function","z":"dc52b959.21afb8","name":"MIDI KNOB PARSE","func":"var knob_array = [];\nknob_array = msg.payload;\nvar output_array = [];\n\nswitch (knob_array[0]) {\n case 48:\n var scaled_value = Math.floor((knob_array[1]*1000)/127);\n output_array[0] = {payload: scaled_value};\n break;\n case 49:\n var scaled_value = Math.floor((knob_array[1]*1000)/127);\n output_array[1] = {payload: scaled_value};\n break;\n case 50:\n var scaled_value = Math.floor((knob_array[1]*1000)/127);\n output_array[2] = {payload: scaled_value};\n break;\n case 51:\n var scaled_value = Math.floor((knob_array[1]*1000)/127);\n output_array[3] = {payload: scaled_value};\n break;\n case 52:\n var scaled_value = Math.floor((knob_array[1]*1000)/127);\n output_array[4] = {payload: scaled_value};\n break;\n case 53:\n var scaled_value = Math.floor((knob_array[1]*1000)/127);\n output_array[5] = {payload: scaled_value};\n break;\n case 54:\n var scaled_value = Math.floor((knob_array[1]*1000)/127);\n output_array[6] = {payload: scaled_value};\n break;\n case 55:\n var scaled_value = Math.floor((knob_array[1]*3000)/127);\n output_array[7] = {payload: scaled_value};\n break;\n \n}\nreturn output_array;\n\n\n","outputs":8,"noerr":0,"x":1453,"y":799.5,"wires":[["88719dee.fa512"],["76bff873.c83658"],["8264833.61d0c8"],["7786ac56.3fb864"],["3dbeeea5.962e02"],["8f69056e.0e6858"],[],["351a1fb5.e0fde","258f8b61.61ffd4"]]},{"id":"b879ed05.75191","type":"ui_slider","z":"dc52b959.21afb8","name":"Servo2","label":"Servo 2","group":"b29a4984.6aeca8","order":2,"width":"0","height":"0","passthru":true,"topic":"Slider","min":0,"max":"1000","step":"1","x":1663,"y":479.5,"wires":[["76bff873.c83658"]]},{"id":"cd47a5aa.4d6b38","type":"ui_slider","z":"dc52b959.21afb8","name":"Preset Recall Speed","label":"Robot Speed","group":"1d707854.547168","order":7,"width":0,"height":0,"passthru":true,"topic":"Slider","min":"500","max":"3000","step":1,"x":1709,"y":679.5,"wires":[["351a1fb5.e0fde","258f8b61.61ffd4"]]},{"id":"9fe16ce9.389b7","type":"ui_slider","z":"dc52b959.21afb8","name":"Servo6","label":"Servo 6","group":"b29a4984.6aeca8","order":6,"width":0,"height":0,"passthru":true,"topic":"Slider","min":0,"max":"1000","step":"1","x":1663,"y":639.5,"wires":[["8f69056e.0e6858"]]},{"id":"d43be5e9.3727e8","type":"ui_slider","z":"dc52b959.21afb8","name":"Servo5","label":"Servo 5","group":"b29a4984.6aeca8","order":5,"width":0,"height":0,"passthru":true,"topic":"Slider","min":0,"max":"1000","step":"1","x":1663,"y":599.5,"wires":[["3dbeeea5.962e02"]]},{"id":"377b3204.a2c96e","type":"ui_slider","z":"dc52b959.21afb8","name":"Servo4","label":"Servo 4","group":"b29a4984.6aeca8","order":4,"width":0,"height":0,"passthru":true,"topic":"Slider","min":0,"max":"1000","step":"1","x":1663,"y":559.5,"wires":[["7786ac56.3fb864"]]},{"id":"eb3eeb15.41b978","type":"ui_slider","z":"dc52b959.21afb8","name":"Servo3","label":"Servo 3","group":"b29a4984.6aeca8","order":3,"width":0,"height":0,"passthru":true,"topic":"Slider","min":0,"max":"1000","step":"1","x":1663,"y":519.5,"wires":[["8264833.61d0c8"]]},{"id":"88719dee.fa512","type":"change","z":"dc52b959.21afb8","name":"save to Global Servos1","rules":[{"t":"set","p":"servos_preset[0]","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1933,"y":439.5,"wires":[[]]},{"id":"76bff873.c83658","type":"change","z":"dc52b959.21afb8","name":"save to Global Servos2","rules":[{"t":"set","p":"servos_preset[1]","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1933,"y":479.5,"wires":[[]]},{"id":"8264833.61d0c8","type":"change","z":"dc52b959.21afb8","name":"save to Global Servos3","rules":[{"t":"set","p":"servos_preset[2]","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1933,"y":519.5,"wires":[[]]},{"id":"7786ac56.3fb864","type":"change","z":"dc52b959.21afb8","name":"save to Global Servos4","rules":[{"t":"set","p":"servos_preset[3]","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1933,"y":559.5,"wires":[[]]},{"id":"3dbeeea5.962e02","type":"change","z":"dc52b959.21afb8","name":"save to Global Servos5","rules":[{"t":"set","p":"servos_preset[4]","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1933,"y":599.5,"wires":[[]]},{"id":"8f69056e.0e6858","type":"change","z":"dc52b959.21afb8","name":"save to Global Servos6","rules":[{"t":"set","p":"servos_preset[5]","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1933,"y":639.5,"wires":[[]]},{"id":"351a1fb5.e0fde","type":"change","z":"dc52b959.21afb8","name":"save to Global RobotSpeed","rules":[{"t":"set","p":"robot_speed","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1943,"y":679.5,"wires":[[]]},{"id":"5fe7f4eb.c1834c","type":"function","z":"dc52b959.21afb8","name":"insert preset","func":"var preset = [];\npreset = global.get(\"servos_preset\");\nvar newMsg = {};\nnewMsg.collection = 'servos_presets';\nnewMsg.payload = [\n {topic: msg.payload},\n {\n \"$set\": {\n \"payload\": preset\n }\n },\n {upsert:true}\n];\n\nreturn newMsg;\n","outputs":1,"noerr":0,"x":958,"y":121,"wires":[["535081ea.4ab9c"]]},{"id":"dea4b3e0.02343","type":"function","z":"dc52b959.21afb8","name":"init global variables","func":"global.set(\"servos_preset\",[500,500,500,500,500,500]); \nmsg.payload = global.get(\"servos_preset\");\nreturn msg;","outputs":1,"noerr":0,"x":973,"y":539.5,"wires":[["666c479b.36fd08","2f7b0534.adfe7a"]]},{"id":"7b300998.70ba68","type":"inject","z":"dc52b959.21afb8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":733,"y":539.5,"wires":[["dea4b3e0.02343"]]},{"id":"666c479b.36fd08","type":"debug","z":"dc52b959.21afb8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1193,"y":539.5,"wires":[]},{"id":"957db32d.bd8d5","type":"debug","z":"dc52b959.21afb8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1193,"y":619.5,"wires":[]},{"id":"32f73dff.e75932","type":"function","z":"dc52b959.21afb8","name":"check global preset","func":"msg.payload = global.get(\"servos_preset\");\nreturn msg;","outputs":1,"noerr":0,"x":973,"y":619.5,"wires":[["957db32d.bd8d5","2f7b0534.adfe7a"]]},{"id":"4c7eed78.081d94","type":"inject","z":"dc52b959.21afb8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":723,"y":619.5,"wires":[["32f73dff.e75932"]]},{"id":"f0e5f5df.8efa68","type":"ui_slider","z":"dc52b959.21afb8","name":"Servo1","label":"Servo 1","group":"b29a4984.6aeca8","order":1,"width":0,"height":0,"passthru":true,"topic":"Slider","min":0,"max":"1000","step":"1","x":1663,"y":439.5,"wires":[["88719dee.fa512"]]},{"id":"be5bb7cc.37df68","type":"function","z":"dc52b959.21afb8","name":"findOne","func":"var newMsg = {};\nnewMsg.operation = 'find.toArray';\nnewMsg.payload = {};\nreturn newMsg;","outputs":1,"noerr":0,"x":845,"y":239,"wires":[["f6cecf8c.a1681"]]},{"id":"330d1133.13b17e","type":"ui_dropdown","z":"dc52b959.21afb8","name":"Recall Pulldown","label":"Recall","place":"Select option","group":"1d707854.547168","order":2,"width":0,"height":0,"passthru":false,"options":[],"payload":"","topic":"","x":1583,"y":239.5,"wires":[["a07e7e4d.e2dd","f2a5a908.f7a208"]]},{"id":"e7284929.d77468","type":"function","z":"dc52b959.21afb8","name":"Format Preset Pulldown","func":"flow.set(\"robot_db_preset\", msg.payload);\nvar msg_array = [];\nfor (var i=0; i< msg.payload.length; i++)\n{\n var tmp_object = {};\n var msg_object = msg.payload[i];\n if (msg_object.topic != undefined){\n tmp_object[msg_object.topic] = {\"topic\": msg_object.topic, \"payload\": msg_object.payload};\n msg_array[i] = tmp_object;\n }\n}\nmsg.options = msg_array;\nreturn msg;","outputs":1,"noerr":0,"x":1350,"y":240,"wires":[["330d1133.13b17e"]]},{"id":"84bb1e9a.882c7","type":"inject","z":"dc52b959.21afb8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":696,"y":237.5,"wires":[["be5bb7cc.37df68"]]},{"id":"3aef48ba.a57b88","type":"ui_text_input","z":"dc52b959.21afb8","name":"","label":"Edit Preset Name","group":"1d707854.547168","order":4,"width":0,"height":0,"passthru":true,"mode":"text","delay":"300","topic":"","x":2013,"y":239.5,"wires":[["c266d6b.ee33a28"]]},{"id":"51857a37.72d9b4","type":"ui_button","z":"dc52b959.21afb8","name":"Save","group":"1d707854.547168","order":5,"width":0,"height":0,"passthru":false,"label":"Save Preset","color":"#FFF","bgcolor":"#FF0000","icon":"","payload":"","payloadType":"date","topic":"","x":638,"y":119.5,"wires":[["58c97ebe.d4c04"]]},{"id":"c266d6b.ee33a28","type":"function","z":"dc52b959.21afb8","name":"set global preset name","func":"global.set(\"robot_arm_preset_name\", msg.payload);","outputs":1,"noerr":0,"x":2223,"y":239.5,"wires":[[]]},{"id":"58c97ebe.d4c04","type":"function","z":"dc52b959.21afb8","name":"save preset","func":"msg.payload = global.get(\"robot_arm_preset_name\");\nreturn msg;","outputs":1,"noerr":0,"x":790,"y":120,"wires":[["5fe7f4eb.c1834c"]]},{"id":"f2a5a908.f7a208","type":"function","z":"dc52b959.21afb8","name":"get preset name","func":"msg.payload = msg.payload.topic;\nreturn msg;","outputs":1,"noerr":0,"x":1803,"y":239.5,"wires":[["3aef48ba.a57b88"]]},{"id":"1d58cd04.fd4743","type":"ui_text","z":"dc52b959.21afb8","group":"1d707854.547168","order":3,"width":0,"height":0,"name":"","label":"SAVE PRESET","format":"{{msg.payload}}","layout":"row-left","x":683,"y":319.5,"wires":[]},{"id":"a87a0242.b6b3f","type":"function","z":"dc52b959.21afb8","name":"delete preset","func":"var newMsg = {};\nnewMsg.operation = 'deleteOne';\nnewMsg.payload = {'topic' : msg.payload};\nreturn newMsg;","outputs":1,"noerr":0,"x":959,"y":180,"wires":[["5712796a.e93028"]]},{"id":"2b13c850.7c7318","type":"ui_button","z":"dc52b959.21afb8","name":"Delete","group":"1d707854.547168","order":5,"width":0,"height":0,"passthru":false,"label":"Delete Preset","color":"#FFF","bgcolor":"#FF00FF","icon":"","payload":"","payloadType":"date","topic":"","x":639,"y":178.5,"wires":[["c1c39a79.6148d8"]]},{"id":"c1c39a79.6148d8","type":"function","z":"dc52b959.21afb8","name":"delete preset","func":"msg.payload = global.get(\"robot_arm_preset_name\");\nreturn msg;","outputs":1,"noerr":0,"x":791,"y":179,"wires":[["a87a0242.b6b3f"]]},{"id":"10a3ed05.bc4e43","type":"debug","z":"dc52b959.21afb8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":943,"y":759.5,"wires":[]},{"id":"b7344ea9.ffe84","type":"function","z":"dc52b959.21afb8","name":"send servo data","func":"var servos = global.get(\"servos_preset\");\nvar last_servos = global.get(\"last_sent_servos\");\nvar sameness_flag = false;\nvar m = [];\n\nfor(var i=0; i<servos.length; i++) {\n if(servos[i]!=last_servos[i]){\n sameness_flag= true;\n }\n}\n\nif(sameness_flag){\n \n var robot_speed = 150;\n\n var servo_string = \"1:\" + servos[0] + \":\" + robot_speed + \"&\" +\n \"2:\" + servos[1] + \":\" + robot_speed + \"&\" +\n \"3:\" + servos[2] + \":\" + robot_speed + \"&\" +\n \"4:\" + servos[3] + \":\" + robot_speed + \"&\" +\n \"5:\" + servos[4] + \":\" + robot_speed + \"&\" +\n \"6:\" + servos[5] + \":\" + robot_speed + \"!\";\n global.set(\"last_sent_servos\", [...servos]);\n m[0] = { payload: servo_string };\n m[1] = { payload: servos};\n return m;\n}\n\n","outputs":2,"noerr":0,"x":2483,"y":839.5,"wires":[["e61aee03.11fb4","e32e2cc3.ba72"],[]]},{"id":"5e2de41.4e2571c","type":"ui_button","z":"dc52b959.21afb8","name":"RESET SERVO POSITIONS","group":"1d707854.547168","order":0,"width":0,"height":0,"passthru":false,"label":"RESET SERVO POSITIONS","color":"","bgcolor":"","icon":"","payload":"1:500:1000&2:500:1000&3:500:1000&4:500:1000&5:500:1000&6:500:1000!","payloadType":"str","topic":"","x":723,"y":379.5,"wires":[["dcb710d9.a9fce"]]},{"id":"dcb710d9.a9fce","type":"function","z":"dc52b959.21afb8","name":"load reset","func":"msg.payload = { payload : [500,500,500,500,500,500] };\nreturn msg;","outputs":1,"noerr":0,"x":1003,"y":399.5,"wires":[["a07e7e4d.e2dd"]]},{"id":"99da116f.01ef5","type":"inject","z":"dc52b959.21afb8","name":"","topic":"","payload":"1000","payloadType":"num","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":1513,"y":699.5,"wires":[["cd47a5aa.4d6b38"]]},{"id":"9fb0cccc.617c2","type":"trigger","z":"dc52b959.21afb8","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"-150","extend":false,"units":"ms","reset":"reset","bytopic":"all","name":"","x":2103,"y":879.5,"wires":[["30979909.84c036","b7344ea9.ffe84"]]},{"id":"7b1deb14.33b0a4","type":"inject","z":"dc52b959.21afb8","name":"","topic":"","payload":"1","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":1893,"y":859.5,"wires":[["9fb0cccc.617c2"]]},{"id":"258f8b61.61ffd4","type":"ui_numeric","z":"dc52b959.21afb8","name":"preset recall speed","label":"numeric","group":"b29a4984.6aeca8","order":0,"width":0,"height":0,"passthru":true,"topic":"","format":"{{value}}","min":0,"max":"1000","step":1,"x":2010,"y":780,"wires":[[]]},{"id":"e234e47a.bf3d58","type":"function","z":"dc52b959.21afb8","name":"save last sent servos","func":"global.set(\"last_sent_servos\", [0,0,0,0,0,0]);\nreturn msg;","outputs":1,"noerr":0,"x":2583,"y":679.5,"wires":[[]]},{"id":"8b2702a9.519bb","type":"inject","z":"dc52b959.21afb8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":2393,"y":679.5,"wires":[["e234e47a.bf3d58"]]},{"id":"2f7b0534.adfe7a","type":"function","z":"dc52b959.21afb8","name":"Reset from global","func":"var preset = [];\nvar m = [];\npreset = global.get(\"servos_preset\");\n\n\nfor (var i=0;i<7;i++)\n{\n m[i] = { payload: preset[i] };\n}\nreturn m;\n","outputs":6,"noerr":0,"x":1433,"y":619.5,"wires":[["f0e5f5df.8efa68"],["b879ed05.75191"],["eb3eeb15.41b978"],["377b3204.a2c96e"],["d43be5e9.3727e8"],["9fe16ce9.389b7"]]},{"id":"cd149163.d8aa9","type":"inject","z":"dc52b959.21afb8","name":"RESET SERVO POSITIONS","topic":"","payload":"1:500:1000&2:500:1000&3:500:1000&4:500:1000&5:500:1000&6:500:1000!","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":743,"y":419.5,"wires":[["dcb710d9.a9fce"]]},{"id":"4b071ae8.11c164","type":"inject","z":"dc52b959.21afb8","name":"reset","topic":"","payload":"reset","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1893,"y":899.5,"wires":[["9fb0cccc.617c2"]]},{"id":"6ed62360.bf7c5c","type":"function","z":"dc52b959.21afb8","name":"get last sent","func":"msg.payload = global.get(\"last_sent_servos\");\n\nreturn msg;","outputs":1,"noerr":0,"x":2553,"y":359.5,"wires":[["b47257b9.4ced88"]]},{"id":"92192add.dec4f8","type":"inject","z":"dc52b959.21afb8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":2383,"y":359.5,"wires":[["6ed62360.bf7c5c"]]},{"id":"67d93db1.497184","type":"function","z":"dc52b959.21afb8","name":"get current","func":"msg.payload = global.get(\"servos_preset\");\nreturn msg;","outputs":1,"noerr":0,"x":2553,"y":419.5,"wires":[["b47257b9.4ced88"]]},{"id":"510ef9f4.29a338","type":"inject","z":"dc52b959.21afb8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":2383,"y":419.5,"wires":[["67d93db1.497184"]]},{"id":"b47257b9.4ced88","type":"debug","z":"dc52b959.21afb8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":2830,"y":380,"wires":[]},{"id":"e61aee03.11fb4","type":"debug","z":"dc52b959.21afb8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":2750,"y":980,"wires":[]},{"id":"30979909.84c036","type":"function","z":"dc52b959.21afb8","name":"get last sent","func":"msg.payload = { last_sent_servos: global.get(\"last_sent_servos\"),\n current_servos: global.get(\"servos_preset\")\n \n};\n\nreturn msg;","outputs":1,"noerr":0,"x":2333,"y":899.5,"wires":[[]]},{"id":"535081ea.4ab9c","type":"mongodb2 in","z":"dc52b959.21afb8","service":"_ext_","configNode":"8f466b3e.ef20b8","name":"Store Data into MongoDB","collection":"robot_arm_presets","operation":"findOneAndUpdate","x":1170,"y":100,"wires":[["be5bb7cc.37df68"]]},{"id":"f6cecf8c.a1681","type":"mongodb2 in","z":"dc52b959.21afb8","service":"_ext_","configNode":"8f466b3e.ef20b8","name":"Mongo DB dynamic operation","collection":"robot_arm_presets","operation":"","x":1079,"y":242,"wires":[["e7284929.d77468","6a0b8411.d481fc"]]},{"id":"5712796a.e93028","type":"mongodb2 in","z":"dc52b959.21afb8","service":"_ext_","configNode":"8f466b3e.ef20b8","name":"Store Data into MongoDB","collection":"robot_arm_presets","operation":"","x":1170,"y":181,"wires":[["be5bb7cc.37df68"]]},{"id":"98b5ccfb.e82dc","type":"serial in","z":"dc52b959.21afb8","name":"","serial":"ba4e05b2.19cda8","x":713,"y":759.5,"wires":[["10a3ed05.bc4e43"]]},{"id":"e32e2cc3.ba72","type":"serial out","z":"dc52b959.21afb8","name":"","serial":"ba4e05b2.19cda8","x":2793,"y":819.5,"wires":[]},{"id":"b3cc39b4.0f4ff8","type":"midi in","z":"dc52b959.21afb8","name":"AKAI APC KEY25 MIDI IN","midiport":"0","x":130,"y":680,"wires":[["788ab250.fbadec"]]},{"id":"332f9ccf.361174","type":"link in","z":"dc52b959.21afb8","name":"","links":["7948db74.494324"],"x":963,"y":319.5,"wires":[[]]},{"id":"80b9f781.aa4e08","type":"debug","z":"dc52b959.21afb8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":670,"y":900,"wires":[]},{"id":"788ab250.fbadec","type":"function","z":"dc52b959.21afb8","name":"filter midi messages by type","func":"var m = [];\nvar type = msg.midi.type;\nif (type == \"controlchange\"){\n m[0] = msg;\n}\nelse if ((type == \"noteon\") || (type == \"noteoff\")) {\n m[1] = msg;\n}\nelse {\n m[2] = msg;\n}\nreturn m;","outputs":3,"noerr":0,"x":400,"y":680,"wires":[["fe156fc2.607ec"],["80b9f781.aa4e08","4f0a82bd.0c772c"],[]]},{"id":"4f0a82bd.0c772c","type":"function","z":"dc52b959.21afb8","name":"save preset with midi keyboard","func":"var m = [];\nvar type = msg.midi.type;\nvar note_num = msg.payload[0];\nif (note_num===93){\n if (type == \"noteon\"){\n flow.set(\"preset_record\", true);\n }\n else if (type == \"noteoff\") {\n flow.set(\"preset_record\", false);\n }\n}\nelse{\n var preset_record = flow.get(\"preset_record\");\n if (preset_record){\n global.set(\"robot_arm_preset_name\", msg.payload[0]);\n m[0] = { payload: 1};\n }\n else {\n m[1] = { payload: msg.payload[0] };\n m[2] = { payload: msg.payload[1] };\n }\n \n}\nreturn m;","outputs":3,"noerr":0,"x":330,"y":560,"wires":[["58c97ebe.d4c04"],["3805ebca.3773b4"],[]]},{"id":"32a43d6b.a332b2","type":"ui_button","z":"dc52b959.21afb8","name":"Load Presets","group":"1d707854.547168","order":5,"width":0,"height":0,"passthru":false,"label":"Load Presets","color":"white","bgcolor":"purple","icon":"","payload":"","payloadType":"date","topic":"","x":510,"y":240,"wires":[["be5bb7cc.37df68"]]},{"id":"3805ebca.3773b4","type":"function","z":"dc52b959.21afb8","name":"trigger pitch preset","func":"var robot_preset = flow.get(\"robot_db_preset\");\nfor(var i = 0;i<robot_preset.length; i++){\n var temp_preset = robot_preset[i];\n if (temp_preset.topic==msg.payload){\n msg.payload = { payload: temp_preset.payload };\n }\n \n}\nreturn msg;","outputs":1,"noerr":0,"x":1130,"y":340,"wires":[["a07e7e4d.e2dd"]]},{"id":"6a0b8411.d481fc","type":"debug","z":"dc52b959.21afb8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1390,"y":340,"wires":[]},{"id":"b29a4984.6aeca8","type":"ui_group","z":"","name":"SERVO SLIDERS","tab":"ccefefa2.1224a","order":3,"disp":true,"width":"6","collapse":false},{"id":"1d707854.547168","type":"ui_group","z":"","name":"PRESETS","tab":"ccefefa2.1224a","order":2,"disp":true,"width":"6","collapse":false},{"id":"8f466b3e.ef20b8","type":"mongodb2","z":0,"uri":"mongodb://127.0.0.1:27017/cinebrain","name":"cinebrain db","options":"","parallelism":"-1"},{"id":"ba4e05b2.19cda8","type":"serial-port","z":0,"serialport":"COM5","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","newline":"\\n","bin":"false","out":"char","addchar":false},{"id":"ccefefa2.1224a","type":"ui_tab","z":"","name":"ROBOT ARM 1","icon":"dashboard","order":7}]