1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

add tick to Unicorn clock example

This commit is contained in:
Dave Conway-Jones 2016-03-29 10:10:12 +01:00
parent a4daf91a30
commit 99e9c540ef
2 changed files with 2 additions and 2 deletions

View File

@ -1 +1 @@
[{"id":"651b51cb.9ae4b","type":"rpi-unicorn","z":"40b203f2.bf4dfc","name":"","png":"0,0,0","bright":"20","x":530,"y":620,"wires":[]},{"id":"d886ebb5.d40378","type":"inject","z":"40b203f2.bf4dfc","name":"","topic":"","payload":"","payloadType":"date","repeat":"10","crontab":"","once":true,"x":100,"y":620,"wires":[["a14fe454.f951f8"]]},{"id":"a14fe454.f951f8","type":"function","z":"40b203f2.bf4dfc","name":"Simple graphical clock","func":"\n// array to hold \"random\" pixels\nvar ranNums = [];\n\n// create a non-overlapping array of random numbers 0-8\nfunction rerand() {\n var nums = [0,1,2,3,4,5,6,7,8];\n var i = nums.length;\n var j;\n ranNums = [];\n while (i--) {\n j = Math.floor(Math.random() * (i+1));\n ranNums.push(nums[j]);\n nums.splice(j,1);\n }\n}\n\n// Get the hours and minutes and split into tens and units\nvar d = new Date();\nvar h = d.getHours();\nvar m = d.getMinutes();\nvar hu = h%10;\nh = parseInt(h/10);\nvar mu = m%10;\nm = parseInt(m/10);\n\n// Do the tens of hours (red)\nrerand();\nnode.send({payload:\"1-3,1-3,0,0,0\"});\nfor (var i=0; i<h; i++) {\n node.send({payload:(1+ranNums[i]%3)+\",\"+(1+parseInt(ranNums[i]/3))+\",255,0,0\"});\n}\n\n// Do the units of hours (green)\nrerand();\nnode.send({payload:\"4-6,1-3,0,0,0\"});\nfor (var i=0; i<hu; i++) {\n node.send({payload:(4+ranNums[i]%3)+\",\"+(1+parseInt(ranNums[i]/3))+\",0,255,0\"});\n}\n\n// Do the tens of minutes (yellow)\nrerand();\nnode.send({payload:\"1-3,4-6,0,0,0\"});\nfor (var i=0; i<m; i++) {\n node.send({payload:(1+ranNums[i]%3)+\",\"+(4+parseInt(ranNums[i]/3))+\",255,255,0\"});\n}\n\n// Do the unit of minutes (blue)\nrerand();\nnode.send({payload:\"4-6,4-6,0,0,0\"});\nfor (var i=0; i<mu; i++) {\n node.send({payload:(4+ranNums[i]%3)+\",\"+(4+parseInt(ranNums[i]/3))+\",0,0,255\"});\n}\n\n// nothing left to do\nreturn null;","outputs":1,"noerr":0,"x":300,"y":620,"wires":[["651b51cb.9ae4b"]]},{"id":"27c3a2e5.082c6e","type":"comment","z":"40b203f2.bf4dfc","name":"Simple graphical clock for Unicorn Hat","info":"Generates a graphical clock, showing hours and minutes. \n\n(count the dots Luke)\n\nUpdates every 10 seconds.\n\nUses the local time of the Pi - you may need to set your local\ntimezone using\n\n sudo dpkg-reconfigure tzdata\n","x":200,"y":580,"wires":[]}] [{"id":"d886ebb5.d40378","type":"inject","z":"40b203f2.bf4dfc","name":"tick","topic":"","payload":"","payloadType":"str","repeat":"3","crontab":"","once":true,"x":90,"y":620,"wires":[["a14fe454.f951f8"]]},{"id":"a14fe454.f951f8","type":"function","z":"40b203f2.bf4dfc","name":"Simple graphical clock","func":"\n// array to hold \"random\" pixels\nvar ranNums = [];\nsu = (context.su || 0);\n\n// create a non-overlapping array of random numbers 0-8\nfunction rerand() {\n var nums = [0,1,2,3,4,5,6,7,8];\n var i = nums.length;\n var j;\n ranNums = [];\n while (i--) {\n j = Math.floor(Math.random() * (i+1));\n ranNums.push(nums[j]);\n nums.splice(j,1);\n }\n}\n\nif (su%4 ===0) {\n // Get the hours and minutes and split into tens and units\n var d = new Date();\n var h = d.getHours();\n var m = d.getMinutes();\n var hu = h%10;\n h = parseInt(h/10);\n var mu = m%10;\n m = parseInt(m/10);\n \n // Do the tens of hours (red)\n rerand();\n node.send({payload:\"1-3,1-3,0,0,0\"});\n for (var i=0; i<h; i++) {\n node.send({payload:(1+ranNums[i]%3)+\",\"+(1+parseInt(ranNums[i]/3))+\",255,0,0\"});\n }\n \n // Do the units of hours (green)\n rerand();\n node.send({payload:\"4-6,1-3,0,0,0\"});\n for (var i=0; i<hu; i++) {\n node.send({payload:(4+ranNums[i]%3)+\",\"+(1+parseInt(ranNums[i]/3))+\",0,255,0\"});\n }\n \n // Do the tens of minutes (yellow)\n rerand();\n node.send({payload:\"1-3,4-6,0,0,0\"});\n for (var i=0; i<m; i++) {\n node.send({payload:(1+ranNums[i]%3)+\",\"+(4+parseInt(ranNums[i]/3))+\",255,255,0\"});\n }\n \n // Do the unit of minutes (blue)\n rerand();\n node.send({payload:\"4-6,4-6,0,0,0\"});\n for (var i=0; i<mu; i++) {\n node.send({payload:(4+ranNums[i]%3)+\",\"+(4+parseInt(ranNums[i]/3))+\",0,0,255\"});\n }\n}\n// Finally add the corner dots for tick/tock\nnode.send({payload:\"0,0,\"+(su===0?\"128,0,128\":\"0,0,0\")+\",7,0,\"+(su===1?\"128,0,128\":\"0,0,0\")+\",7,7,\"+(su===2?\"128,0,128\":\"0,0,0\")+\",0,7,\"+(su===3?\"128,0,128\":\"0,0,0\")})\n\ncontext.su = (su +1) % 4;\n// nothing left to do\nreturn null;","outputs":1,"noerr":0,"x":300,"y":620,"wires":[["651b51cb.9ae4b"]]},{"id":"27c3a2e5.082c6e","type":"comment","z":"40b203f2.bf4dfc","name":"Simple graphical clock for Unicorn Hat","info":"Generates a graphical clock, showing hours and minutes. \n\nHours are shown by the red and green pixels, minutes\nare the yellow and blue pixels.\n\n\nUses the local time of the Pi - you may need to set your local\ntimezone using\n\n sudo dpkg-reconfigure tzdata\n","x":200,"y":580,"wires":[]},{"id":"651b51cb.9ae4b","type":"rpi-unicorn","z":"40b203f2.bf4dfc","name":"","png":"0,0,0","bright":"20","x":510,"y":620,"wires":[]},{"id":"b2ab1d43.0cbeb","type":"inject","z":"40b203f2.bf4dfc","name":"click to rotate","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":110,"y":660,"wires":[["6a7619b6.3bbc68"]]},{"id":"6a7619b6.3bbc68","type":"function","z":"40b203f2.bf4dfc","name":"Rotate","func":"\n// get the current rotation\nvar rot = context.rot || 0;\n// add 90 and get modulus 360\nrot = (rot + 90) % 360;\n// save the new rotation value\ncontext.rot = rot;\n// send the rotation command\nmsg.payload = \"rotate,\"+rot;\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":660,"wires":[["651b51cb.9ae4b"]]}]

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-pi-unicorn-hat", "name" : "node-red-node-pi-unicorn-hat",
"version" : "0.0.11", "version" : "0.0.12",
"description" : "A Node-RED node to output to a Raspberry Pi Unicorn HAT from Pimorini.", "description" : "A Node-RED node to output to a Raspberry Pi Unicorn HAT from Pimorini.",
"dependencies" : { "dependencies" : {
"pngjs": "2.2.*" "pngjs": "2.2.*"