var count = context.get('count')||0;
var temp;
count += 1;
if((count%2)===0)
{
temp=1;
}
else
{
temp=0;
}
context.set('count',count);
msg.payload=temp;
return msg;
程序代码,使用"导入"
[{
"id": "6479b324.c603ac",
"type": "function",
"z": "15320658.89a65a",
"name": "计数取余函数",
"func": "var count = context.get('count')||0;\nvar temp;\ncount += 1;\nif((count%2)===0)\n {\n temp=1;\n }\n else\n {\n temp=0;\n } \n context.set('count',count);\n msg.payload=temp;\n return msg;",
"outputs": 1,
"noerr": 0,
"x": 300,
"y": 180,
"wires": [
["cbdcee7b.1849f", "217dc0f2.f49e8"]
]
}]