2021年1月2日 星期六

Node-Red 亂數折線圖 與 正弦函數(sin)、餘弦函數(cos)

 Node-Red 亂數折線圖 與 正弦函數(sin)、餘弦函數(cos)




0~100亂數產生器

High =100;

Low =0 ;

msg.payload= Math.floor(Math.random() * (1 + High - Low)) + Low ;

return msg;

正弦函數

var t=context.get("t") || 0;

t+=1;

if (t>=30) t=0;

context.set("t",t);

msg.payload=Math.sin(2*3.14*t/30)*2

msg.topic="正弦函數(SIN)"

return msg;


Node-Red 程式1

[{"id":"8641eeea.a88db","type":"function","z":"8929f3b6.359b7","name":"正弦函數","func":"var t=context.get(\"t\") || 0;\nt+=1;\nif (t>=30) t=0;\n\ncontext.set(\"t\",t);\nmsg.payload=Math.sin(2*3.14*t/30)*2\nmsg.topic=\"正弦函數(SIN)\"\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":400,"y":200,"wires":[["53922be0.0de314"]]},{"id":"53922be0.0de314","type":"ui_chart","z":"8929f3b6.359b7","name":"","group":"b0cdcace.9d4b08","order":63,"width":0,"height":0,"label":"chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"-2","ymax":"2","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"x":600,"y":200,"wires":[[]]},{"id":"95ea2c5a.b1971","type":"inject","z":"8929f3b6.359b7","name":"1秒鐘 Timer","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":220,"wires":[["8641eeea.a88db","db4f7a11.756e38"]]},{"id":"db4f7a11.756e38","type":"function","z":"8929f3b6.359b7","name":"餘弦函數 ","func":"var t=context.get(\"t\") || 0;\nt+=1;\nif (t>=30) t=0;\n\ncontext.set(\"t\",t);\nmsg.payload=Math.cos(2*3.14*t/30)*2\nmsg.topic=\"ˊ餘弦函數(COS)\"\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":400,"y":260,"wires":[["53922be0.0de314"]]},{"id":"f6c41572.0eac18","type":"inject","z":"8929f3b6.359b7","name":"清除","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":210,"y":320,"wires":[["83e16076.d60d"]]},{"id":"4e09de45.263e7","type":"ui_button","z":"8929f3b6.359b7","name":"","group":"b0cdcace.9d4b08","order":62,"width":0,"height":0,"passthru":false,"label":"清除","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":210,"y":360,"wires":[["83e16076.d60d"]]},{"id":"83e16076.d60d","type":"function","z":"8929f3b6.359b7","name":"","func":"msg.payload=[];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":420,"y":320,"wires":[["53922be0.0de314"]]},{"id":"b0cdcace.9d4b08","type":"ui_group","name":"Num","tab":"53b8c8f9.cfbe48","order":6,"disp":true,"width":"6","collapse":false},{"id":"53b8c8f9.cfbe48","type":"ui_tab","name":"Home","icon":"dashboard","order":2,"disabled":false,"hidden":false}]


Node-Red 程式2

[{"id":"9ddd46f4.de3678","type":"function","z":"8bd90afd.137db8","name":"0~100亂數產生器","func":"High =100;\nLow =0 ;\nmsg.payload= Math.floor(Math.random() * (1 + High - Low)) + Low ;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":390,"y":180,"wires":[["5cc339e6.103f08","3401eeb6.c22022"]]},{"id":"5c26f043.9e928","type":"inject","z":"8bd90afd.137db8","name":"5秒鐘 Timer","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":180,"wires":[["9ddd46f4.de3678"]]},{"id":"31676d8e.5aa592","type":"inject","z":"8bd90afd.137db8","name":"清除","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":260,"wires":[["b978b1dc.17eb7"]]},{"id":"b978b1dc.17eb7","type":"function","z":"8bd90afd.137db8","name":"","func":"msg.payload=[];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":260,"wires":[["3401eeb6.c22022"]]},{"id":"5cc339e6.103f08","type":"debug","z":"8bd90afd.137db8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":610,"y":180,"wires":[]},{"id":"3401eeb6.c22022","type":"ui_chart","z":"8bd90afd.137db8","name":"","group":"4bd6d6a5.234c38","order":61,"width":0,"height":0,"label":"折線圖","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"100","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"60","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"x":550,"y":240,"wires":[[]]},{"id":"f9417d5a.c4b1c","type":"ui_button","z":"8bd90afd.137db8","name":"","group":"4bd6d6a5.234c38","order":61,"width":"0","height":"0","passthru":false,"label":"清除折線圖","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":160,"y":320,"wires":[["b978b1dc.17eb7"]]},{"id":"4bd6d6a5.234c38","type":"ui_group","name":"Default","tab":"53b8c8f9.cfbe48","order":5,"disp":true,"width":"6","collapse":true},{"id":"53b8c8f9.cfbe48","type":"ui_tab","name":"Home","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

沒有留言:

張貼留言

WOKWI LED + MQTT Node-Red SQLite

WOKWI LED + MQTT Node-Red SQLite const char *mqtt_broker = "broker.mqtt-dashboard.com" ; const char *topic1 = "alex9ufo/e...