Analog Random Values Implementation Script. | Node-Red Flow Example
//===setting===
var hpoint = 100;
var lpoint = 0;
var cent = 10; //centralize number
//===============
var mpoint = 0;
var output = context.get('output')||0;
var addpoint = context.get('addpoint')||0;
//count
var count = context.get('count')||0;
count += 1;
context.set('count',count);
//rcount
var rcount = context.get('rcount')||0;
if(count >= rcount){
for(i=0;i<cent;i++){ //centralize
mpoint = mpoint + Math.floor(Math.random() * hpoint);
}
rcount = parseInt(Math.floor(Math.random() * 100)/5);
addpoint = ((mpoint/cent)-output)/rcount;
context.set('addpoint',addpoint);
context.set('rcount',rcount);
context.set('count',0);
}else{
output = parseFloat((output + addpoint).toFixed(1));
context.set('output',output);
}
msg.payload = output;
return msg;
Flow JSON Sourcecode
[{"id":"59e7f383.6f34ec","type":"comment","z":"35516ee7.622d92","name":"Random","info":"","x":220,"y":100,"wires":[]},{"id":"a38db82b.383e78","type":"inject","z":"35516ee7.622d92","name":"","topic":"","payload":"","payloadType":"date","repeat":"2","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":160,"wires":[["f49a2ffd.11127"]]},{"id":"a99544a8.554ed8","type":"debug","z":"35516ee7.622d92","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":630,"y":220,"wires":[]},{"id":"f49a2ffd.11127","type":"function","z":"35516ee7.622d92","name":"random","func":"//===setting=== \nvar hpoint = 100;\nvar lpoint = 0;\nvar cent = 10; //centralize number\n//===============\n\nvar mpoint = 0;\nvar output = context.get('output')||0;\nvar addpoint = context.get('addpoint')||0;\n\n//count\nvar count = context.get('count')||0;\ncount += 1;\ncontext.set('count',count);\n\n//rcount\nvar rcount = context.get('rcount')||0;\nif(count >= rcount){\n for(i=0;i<cent;i++){ //centralize\n mpoint = mpoint + Math.floor(Math.random() * hpoint);\n }\n rcount = parseInt(Math.floor(Math.random() * 100)/5);\n addpoint = ((mpoint/cent)-output)/rcount;\n context.set('addpoint',addpoint);\n context.set('rcount',rcount);\n context.set('count',0);\n}else{\n output = parseFloat((output + addpoint).toFixed(1));\n context.set('output',output);\n}\nmsg.payload = output;\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":160,"wires":[["a99544a8.554ed8","7f105c44.bf22e4"]]},{"id":"7f105c44.bf22e4","type":"ui_chart","z":"35516ee7.622d92","name":"","group":"7784c75b.8caac8","order":0,"width":"6","height":"6","label":"chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"200","removeOlder":1,"removeOlderPoints":"50","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":610,"y":160,"wires":[[],[]]},{"id":"7784c75b.8caac8","type":"ui_group","z":"","name":"Default","tab":"ef07f6d1.ceaea8","disp":true,"width":"6","collapse":false},{"id":"ef07f6d1.ceaea8","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]
訂閱:
張貼留言 (Atom)
2024_09 作業3 以Node-Red 為主
2024_09 作業3 (以Node-Red 為主 Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker 2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...
-
python pip 不是内部或外部命令 -- 解決方法 要安裝 Pyqt5 1. 首先,開啟命令提示字元。 2. 輸入 pip3 install pyqt5 好像不能執行 ! ! 錯誤顯示 : ‘ pip3 ’ 不是內部或外部命令、可執行的程式或批...
-
課程講義 下載 11/20 1) PPT 下載 + 程式下載 http://www.mediafire.com/file/cru4py7e8pptfda/106%E5%8B%A4%E7%9B%8A2-1.rar 11/27 2) PPT 下載...
-
• 認 識 PreFix、InFix、PostFix PreFix(前序式):* + 1 2 + 3 4 InFix(中序式): (1+2)*(3+4) PostFix(後序式):1 2 + 3 4 + * 後 序式的運算 例如: 運算時由 後序式的...
沒有留言:
張貼留言