Skip to content

Instantly share code, notes, and snippets.

@kn1cht
Created December 11, 2019 15:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kn1cht/99579459ba69a6b4d4c840e3ea2f8981 to your computer and use it in GitHub Desktop.
Save kn1cht/99579459ba69a6b4d4c840e3ea2f8981 to your computer and use it in GitHub Desktop.
noodl-obniz-js-test
{
"name": "obniz-js-test",
"components": [
{
"name": "/Main",
"graph": {
"connections": [
{
"fromId": "2fac9a62-40b9-03a1-6a8a-e06562dc9f73",
"fromProperty": "isAddedToDOM",
"toId": "d46a899b-21ec-d860-9215-51d782dd5fa0",
"toProperty": "isAddedToDOM"
},
{
"fromId": "2fac9a62-40b9-03a1-6a8a-e06562dc9f73",
"fromProperty": "domElement",
"toId": "d46a899b-21ec-d860-9215-51d782dd5fa0",
"toProperty": "domElement"
},
{
"fromId": "ce2516ca-8776-8f62-d7e7-80fba7d51c58",
"fromProperty": "loaded",
"toId": "d46a899b-21ec-d860-9215-51d782dd5fa0",
"toProperty": "scriptsLoaded"
},
{
"fromId": "40bf33c4-06db-0eaf-757c-30ebf3fb6d84",
"fromProperty": "savedValue",
"toId": "d46a899b-21ec-d860-9215-51d782dd5fa0",
"toProperty": "obnizId"
}
],
"roots": [
{
"id": "ce2516ca-8776-8f62-d7e7-80fba7d51c58",
"type": "Script Downloader",
"x": -73,
"y": 345,
"parameters": {
"input 0": "https://obniz.io/js/jquery-3.2.1.min.js",
"input 1": "https://unpkg.com/obniz@2.5.0/obniz.js"
},
"ports": [],
"dynamicports": [],
"children": []
},
{
"id": "2d3ccd33-f1ef-2dc5-3e1a-ca9d61cd222b",
"type": "Group",
"label": "Root",
"x": 260,
"y": 114,
"parameters": {
"fill": "parent"
},
"ports": [],
"dynamicports": [],
"children": [
{
"id": "fa90ea16-1232-0437-deea-5dd6263d8247",
"type": "Rectangle",
"label": "Background",
"x": 20,
"y": 61,
"parameters": {},
"ports": [],
"dynamicports": [],
"children": []
},
{
"id": "2fac9a62-40b9-03a1-6a8a-e06562dc9f73",
"type": "HTML Content",
"x": 20,
"y": 122,
"parameters": {
"html": "<!DOCTYPE html>\n<head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <link rel=\"stylesheet\" href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css\">\n <link rel=\"stylesheet\" href=\"https://obniz.io/css/starter-sample.css\">\n \n</head>\n<body>\n\n<div id=\"obniz-debug\"></div>\n\n<div class=\"wrap\">\n <div class=\"print\">\n <h3 class=\"text-center\">Print words on obniz</h3>\n <div>\n <input type=\"text\" id=\"text\" value=\"Hello World\" placeholder=\"Input in freely\">\n <button class=\"btn btn-primary\" id=\"showtime\">Print on obniz</button>\n </div>\n </div>\n\n <div class=\"switch\">\n <h3 class=\"text-center\"> Swtich </h3>\n <span id=\"print\">undefined</span>\n </div>\n\n <div class=\"led\">\n <h3 class=\"text-center\">Turning on a LED</h3>\n <button class=\"btn btn-primary\" id=\"on\">LED ON</button>\n <button class=\"btn btn-outline-primary\" id=\"off\">LED OFF</button>\n <dl>\n <dt>Demo Pin assign</dt>\n <dd>- io0:LED anode</dd>\n <dd>- io1:LED cathode</dd>\n <dd>- Switch state will be printed on browser</dd>\n </dl>\n </div>\n</div>\n\n</body>"
},
"ports": [],
"dynamicports": [],
"children": []
}
]
},
{
"id": "d46a899b-21ec-d860-9215-51d782dd5fa0",
"type": "Javascript2",
"x": 104,
"y": 237,
"parameters": {
"code": "define({\n inputs: {\n isAddedToDOM : \"boolean\",\n domElement : \"domelement\",\n scriptsLoaded: \"boolean\",\n obnizId: \"string\"\n },\n outputs: {\n outputValue: \"number\"\n },\n destroy: function(inputs, outputs) {\n\n },\n setup: function(inputs, outputs) {\n\n },\n run: function(inputs, outputs, changedInputs) {\n var obniz = new Obniz;\n // var obniz = new Obniz(inputs.obnizId); // Swap this line with previous one if you pass obniz id as inputs.\n obniz.onconnect = function () {\n var led = obniz.wired(\"LED\", {anode: 0, cathode: 1});\n obniz.display.clear();\n obniz.display.print(\"Hello World\");\n \n obniz.switch.onchange = function (state) {\n $('#print').text(state);\n obniz.display.clear();\n obniz.display.print(state);\n };\n \n $(\"#showtime\").on(\"click\", function () {\n obniz.display.clear();\n obniz.display.print($(\"#text\").val());\n });\n \n $('#on').click(function () {\n led.on();\n obniz.display.clear();\n obniz.display.print(\"ON\");\n });\n \n $('#off').click(function () {\n led.off();\n obniz.display.clear();\n obniz.display.print(\"OFF\");\n });\n };\n }\n});"
},
"ports": [],
"dynamicports": [
{
"name": "isAddedToDOM",
"plug": "input",
"type": {
"name": "boolean"
},
"group": "Inputs",
"index": 2
},
{
"name": "domElement",
"plug": "input",
"type": {
"name": "domelement"
},
"group": "Inputs",
"index": 3
},
{
"name": "scriptsLoaded",
"plug": "input",
"type": {
"name": "boolean"
},
"group": "Inputs",
"index": 4
},
{
"name": "obnizId",
"plug": "input",
"type": {
"name": "string"
},
"group": "Inputs",
"index": 5
},
{
"name": "outputValue",
"type": {
"name": "number"
},
"plug": "output",
"group": "Outputs",
"index": 6
}
],
"children": []
},
{
"id": "40bf33c4-06db-0eaf-757c-30ebf3fb6d84",
"type": "String",
"label": "INPUT YOUR OBNIZ ID",
"x": -76,
"y": 229,
"parameters": {
"value": ""
},
"ports": [],
"dynamicports": [],
"children": []
}
]
}
}
],
"settings": {
"devices": "Default Device",
"Default Device.fillMode": "aspectFit",
"Default Device.canvasWidth": 1080,
"Default Device.canvasHeight": 1920
},
"rootNodeId": "2d3ccd33-f1ef-2dc5-3e1a-ca9d61cd222b",
"version": "1"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment